/*--------------Global Functional Variables---------------*/
    var kongregate
    var flurryAnalytics
    var NumberSystem = "Mixed"
    var HUinterval;
    var HUtimeout;
    var AutoSpinTimer
    var AutoStopTimer
    var AutoStopInterval
    var InterACH
    var BelieverAlert = "On"
    var StoreAlert = "On"
    var CompAlert="On"
    var SpinNum = 0
    var CompanyMan = "Makopaz"
    var CMamt = 68
    var LeaderCheck
    var Save
    var StatusRenew
    var MinorVersion = 1.028
    var RatingCheck
/*--------------Global Useful Functions---------------*/
    function getBaseLog(thenumber, base) {
        return Math.log(thenumber) / Math.log(base);
    }

    function DisplayLarge(BigNumber) {
        var TheKey = {
            0: '',
            1: 'K',
            2: 'M',
            3: 'B',
            4: 'T',
            5: 'q',
            6: 'Q',
            7: 's',
            8: 'S',
            9: 'Oc',
            10: 'N',
            11: 'd',
            12: 'Ud',
            13: 'Dd',
            14: 'Td',
            15: 'qd',
            16: 'Qd',
            17: 'sd',
            18: 'Sd',
            19: 'Od',
            20: 'Nd',
            21: 'vg',
            22: 'Uv',
            23: 'Dv',
            24: 'Tv',
            25: 'qv',
            26: 'Qv',
            27: 'sv',
            28: 'Sv',
            29: 'Ov',
            30: 'Nv',
            31: 'tg',
            32: 'Ut',
            33: 'Dt',
            34: 'Tt',
            35: 'qt',
            36: 'Qt',
            37: 'st',
            38: 'St',
            39: 'Ot',
            40: 'Nt',
            41: 'qdg',
            42: 'Uq',
            43: 'Dq',
            44: 'Tq',
            45: 'qq',
            46: 'Qq',
            47: 'sq',
            48: 'Sq',
            49: 'Oq',
            50: 'Nq',
            51: 'Qn',
            52: 'UQ',
            53: 'DQ',
            54: 'TQ',
            55: 'qQ',
            56: 'QQ',
            57: 'sQ',
            58: 'SQ',
            59: 'OQ',
            60: 'NQ',
            61: 'sg',
            62: 'Us',
            63: 'Ds',
            64: 'Ts',
            65: 'qs',
            66: 'Qs',
            67: 'ss',
            68: 'Ss',
            69: 'Os',
            70: 'Ns',
            71: 'Sg',
            72: 'US',
            73: 'DS',
            74: 'TS',
            75: 'qS',
            76: 'QS',
            77: 'sS',
            78: 'SS',
            79: 'OS',
            80: 'NS',
            81: 'Og',
            82: 'UO',
            83: 'DO',
            84: 'TO',
            85: 'qO',
            86: 'QO',
            87: 'sO',
            88: 'SO',
            89: 'OO',
            90: 'NO',
            91: 'Ng',
            92: 'UN',
            93: 'DN',
            94: 'TN',
            95: 'qN',
            96: 'QN',
            97: 'sN',
            98: 'SN',
            99: 'ON',
            100: 'NN',
            101: 'C'
        }
        var MixedBack = false
        if(NumberSystem == "Mixed"){
            MixedBack = true
            if(Number(BigNumber)>1e36){
                NumberSystem = "Scientific"
            }else{
                NumberSystem = "Names"
            }
        }
        if(NumberSystem == "Names"){
            var regularPower = getBaseLog(BigNumber, 1000)
            var thePower = Math.floor(regularPower)
            var simpleNumber = BigNumber / (Math.pow(1000, thePower))
            var result = ""

            if (BigNumber == 0) {
                result = 0
            } else if (regularPower < 1.34 && Number(BigNumber)>=1) {
                result = BigNumber.toFixed(0)
                /*if(NYUpgrades.CardTransM=="yes"&&BigNumber<100){
                    result = BigNumber.toFixed(2)
                }*/
            }else if(Number(BigNumber)<1 && Number(BigNumber)>0){
                result = BigNumber.toFixed(2)
            } else if (regularPower % 1 > .33) {
                result = simpleNumber.toFixed(1) + TheKey[thePower]
            } else {
                result = simpleNumber.toFixed(2) + TheKey[thePower]
            }

            if(thePower>101){
                result = Infinity
            }
        }else if(NumberSystem == "Scientific"){
            if(Number(BigNumber)<1000 && Number(BigNumber)>=1){
                result = BigNumber.toFixed(0)
                /*if(NYUpgrades.CardTransM=="yes"&&BigNumber<100){
                    result = BigNumber.toFixed(2)
                }*/
            }else if(Number(BigNumber)<1 && Number(BigNumber)>0){
                result = BigNumber.toFixed(2)
            }else if (Number(BigNumber) == 0) {
                result = 0
            }else{
                result = String(Number(BigNumber).toExponential(2)).replace("+","")
            }
        }
        if(MixedBack){
            NumberSystem = "Mixed"
        }
        
        return result
    }
    function ReadLarge(BigNumber){
        var SuffixKey = {
            'K': 1,
            'M': 2,
            'B': 3,
            'T': 4,
            'q': 5,
            'Q': 6,
            's': 7,
            'S': 8,
            'Oc': 9,
            'N': 10,
            'd': 11,
            'Ud': 12,
            'Dd': 13,
            'Td': 14,
            'qd': 15,
            'Qd': 16,
            'sd': 17,
            'Sd': 18,
            'Od': 19,
            'Nd': 20,
            'vg': 21,
            'Uv': 22,
            'Dv': 23,
            'Tv': 24,
            'qv': 25,
            'Qv': 26,
            'sv': 27,
            'Sv': 28,
            'Ov': 29,
            'Nv': 30,
            'tg': 31,
            'Ut': 32,
            'Dt': 33,
            'Tt': 34,
            'qt': 35,
            'Qt': 36,
            'st': 37,
            'St': 38,
            'Ot': 39,
            'Nt': 40,
            'qdg': 41,
            'Uq': 42,
            'Dq': 43,
            'Tq': 44,
            'qq': 45,
            'Qq': 46,
            'sq': 47,
            'Sq': 48,
            'Oq': 49,
            'Nq': 50,
            'Qn': 51,
            'UQ': 52,
            'DQ': 53,
            'TQ': 54,
            'qQ': 55,
            'QQ': 56,
            'sQ': 57,
            'SQ': 58,
            'OQ': 59,
            'NQ': 60,
            'sg': 61,
            'Us': 62,
            'Ds': 63,
            'Ts': 64,
            'qs': 65,
            'Qs': 66,
            'ss': 67,
            'Ss': 68,
            'Os': 69,
            'Ns': 70,
            'Sg': 71,
            'US': 72,
            'DS': 73,
            'TS': 74,
            'qS': 75,
            'QS': 76,
            'sS': 77,
            'SS': 78,
            'OS': 79,
            'NS': 80,
            'Og': 81,
            'UO': 82,
            'DO': 83,
            'TO': 84,
            'qO': 85,
            'QO': 86,
            'sO': 87,
            'SO': 88,
            'OO': 89,
            'NO': 90,
            'Ng': 91,
            'UN': 92,
            'DN': 93,
            'TN': 94,
            'qN': 95,
            'QN': 96,
            'sN': 97,
            'SN': 98,
            'ON': 99,
            'NN': 100,
            'C': 101,
            'Infinity': Infinity,
            '': 0
        }
        if(isNaN(Number(BigNumber))){
            var TheNumbers = Number(BigNumber.replace(/[^\d.-]/g,''));
            var TheText = BigNumber.replace(/[0-9,.]/g,'');
            var FullNumber
            //if(TheNumbers != "" && TheText != ""){
            if(BigNumber!="Infinity"){
                FullNumber = TheNumbers*Math.pow(1000,SuffixKey[TheText])
            }else{
                FullNumber = Infinity
            }
        }else{
            var FullNumber = Number(BigNumber)
        }
        
        return FullNumber
    }

    function FixNumbers(){
        $(".Cost,.Salary,#StoreCost,.TotalAMT,#Believers,#StoreHint").each(function(){
            if($(this).hasClass("SMC")){
                //Do Nothing
            }else{
                NumberFix($(this))
            }
        })
        AllChecks()
    }
    function NumberFix(theElement){
        var Reader = ReadLarge(theElement.html())
        theElement.html(DisplayLarge(Reader))
    }

    function Analytics(eType,eAction,eOther){
        var EventCategory = ""
        var EventAction = eAction
        var EventLabel = ""
        if(eOther["event_category"]){
            EventCategory = eOther["event_category"]
        }
        if(eOther["event_label"]){
            EventLabel = eOther["event_label"]
        }
        if(gtag){
            gtag(eType,eAction,eOther)
        }
    }

/*--------------Program Initialization---------------*/
    function Opening() {
        //InitScratch("#FirstScratch")
        //MakeResult("#FirstScratch")
        Hooks()
        GameHooks()
        $(".slot").show()
        SlotsInit()
        LoadData()
        if(kongregateAPI){
            kongregateAPI.loadAPI(onComplete)
        }
        Save = setInterval(SaveData,3000)
        //ResetScratch("#FirstScratch")
        var LeaderStart = setTimeout(LeaderChecker,2000)
        LeaderCheck = setInterval(LeaderChecker,300000)
        StatusRenew = setInterval(AnaStatus,250000)
        RatingCheck = setInterval(GetRating,600000)
        //CloudLogin = setInterval(BasicCloudLogin,30000)
        //BasicCloudLogin()
    }
    function AnaStatus(){
        Analytics('event', 'Status Renew', {'event_category':"Page Actions"})
    }
    function LeaderChecker(){
        $.getJSON('https://api.kongregate.com/api/high_scores/weekly/139868.json', function(data) {
            CompanyMan = data.weekly_scores[1].username
            CMamt = data.weekly_scores[1].score
        });
    }
    function GetRating(){
        $.getJSON("https://cors-anywhere.herokuapp.com/https://www.kongregate.com/games/makopaz/holiday-slots-inc/metrics.json",function(data){
            Analytics('event', 'Rating',{'event_category':"Game Data",'value':Number(data.rating)*100})
        })
    }
    function BasicCloudLogin(){
        if(kongregate){
            PlayFab.settings.titleId = "A7350";
            var loginRequest = {
                TitleId: PlayFab.settings.titleId,
                KongregateId: kongregate.services.getUserId(),
                AuthTicket: kongregate.services.getGameAuthToken(),
                CreateAccount: true
            };
            PlayFabClientSDK.LoginWithKongregate(loginRequest,function(result,error){
                if (result !== null) {
                    PlayFabClientSDK.UpdateUserTitleDisplayName({"DisplayName": kongregate.services.getUsername()})
                    console.log("Cloud Connection Stable")
                    PlayFabClientSDK.GetUserData({"Keys": ["Storage"]}, 
                        function(result,error){
                            if (error !== null) {
                                console.log("Something went wrong with your savetime load\n" +
                                    "Here's some debug information:\n" +
                                    PlayFab.GenerateErrorReport(error))
                                //console.log(error)
                                $(".LastSaved").html("No Cloud Save Detected")
                            } else if (result !== null) {
                                PlayFabData = JSON.parse(result.data.Data.Storage.Value)
                                var LastSaved = Number(atob(PlayFabData.STT))
                                var SinceLast = (Number(new Date()) - LastSaved)/60000
                                var DisplayTime = (SinceLast/60).toFixed(1) + " Hours"
                                if((SinceLast/60)<1){
                                    DisplayTime = SinceLast.toFixed(0) + " Minutes"
                                }else if((SinceLast/60)>24){
                                    DisplayTime = (SinceLast/(24*60)).toFixed(1) + " Days"
                                }
                                $(".LastSaved").html("Last Cloud Save: "+DisplayTime+" Ago")
                                console.log("done")
                            }
                        })
                } else if (error !== null) {
                    console.log("Something went wrong with your cloud connection\n" +
                        "Here's some debug information:\n" +
                        PlayFab.GenerateErrorReport(error))
                    $(".LastSaved").html("No Cloud Save Detected")
                }
            });
        }
    }
    function onComplete(){
        // Set the global kongregate API object
        kongregate = kongregateAPI.getAPI();
        kongregate.mtx.requestUserItemList(kongregate.services.getUsername(), Purchases)
        BasicCloudLogin()
        if(gtag){
            if(document.referrer.includes("https://www.kongregate.com/games/Makopaz")){
                gtag('config', 'UA-146113740-6',{'page_title' : 'HSI Version '+MinorVersion.toFixed(3),
                                                'page_location':document.referrer+"&Version="+MinorVersion.toFixed(3),
                                                'page_path': document.referrer.replace("https://www.kongregate.com/games/Makopaz","")+"&Version="+MinorVersion.toFixed(3)})
            }else{
                gtag('config', 'UA-146113740-6',{'page_title' : 'HSI Version '+MinorVersion.toFixed(3),
                                                'page_location':"https://www.kongregate.com/games/Makopaz/holiday-slots-inc&Version="+MinorVersion.toFixed(3),
                                                'page_path':"/holiday-slots-inc&Version="+MinorVersion.toFixed(3)})
            }
        }
    }
    function Hooks() {
        $('img').attr('draggable', false)
        $("#CloudSave").on('click', function() {
            CloudAccess("Save")
        })
        $("#CloudLoad").on('click', function() {
            CloudAccess("Load")
        })
        $("#AndroidPromo").on('click', function() {
            Analytics('event', 'Android',{'event_category':"Get App"})
        })
        $("#SubReddit").on('click', function() {
            Analytics('event', 'SubReddit',{'event_category':"Social"})
        })
        $(".PopupHolder").on('click', function(e) {
            var TargetElement = e.target
            var TargetClass = TargetElement.className
            if(TargetClass == "Close" || TargetClass == "PopupHolder"){
                if($("#AchievePopup").is(":visible")&&$(".PopupHolder .Popup:visible").length>1){
                    $("#AchievePopup").hide()
                }else{
                    $(".Popup").hide()
                    $(".PopupHolder").hide()
                }
                clearInterval(InterACH)
            }
        })
        $(".BottomButton").on('click', function() {
            var popupID = "#" + $(this).attr("id").replace("Menu", "")+"Popup"
            $(".PopupHolder").show()
            $(popupID).show()
            Analytics('event', 'Show Popup', {'event_category':"Open Menu", 'event_label': popupID.replace("#","") })
        })
        $(".PayoutHolder").on('click', function(e) {
            var TargetElement = e.target
            var TargetClass = TargetElement.className
            if(TargetClass == "Close" || TargetClass == "PayoutHolder"){
                $(this).hide()
            }
        })
        $(".BasicPopHolder").on('click', function(e) {
            var TargetElement = e.target
            var TargetClass = TargetElement.className
            if($("#BasicPopup").is(":visible")){
                if(TargetClass == "Close" ||TargetClass == "BasicPopHolder"||TargetClass == "InfoButton"){
                    $(this).hide()
                }
            }else{
                if(TargetClass == "Close" ||/*TargetClass == "BasicPopHolder"||*/TargetClass == "InfoButton"){
                    $(this).hide()
                }
            }
        })
        $("#PayoutButton").on('click', function() {
            $(".PayoutHolder").show()
            $("#PayoutPopup").show()
            Analytics('event', 'Show Popup', {'event_category':"Open Menu", 'event_label': popupID.replace("#","") })
        })
        $(".InfoButton#NumberSystem").on('click', function() {
            if(NumberSystem == "Mixed"){
                NumberSystem = "Names"
            }else if(NumberSystem == "Names"){
                NumberSystem = "Scientific"
            }else if(NumberSystem == "Scientific"){
                NumberSystem = "Mixed"
            }
            $("#NumberType").html(NumberSystem)
            FixNumbers()
            Analytics('event', 'Number System',{'event_category':"Settings",'event_label': NumberSystem})
        })
        $('html').bind('keypress', function(e){
            if(e.keyCode == 13){
                return false;
            }
        })
    }
    function BasicPopup(title,content){
        $(".BasicPopHolder").show()
        $(".BasicPopHolder .Popup").hide()
        $("#BasicPopup").show()
        $("#BasicPopup").find(".PopTitle").html(title)
        $("#BasicPopup").find(".MenuOverview").html(content)
        $("#BasicPopup").css("height",$("#BasicPopup .MenuOverview").height()+140)
        //Fix Mobile
            $("#BasicPopup").css("margin-top",(720-$("#BasicPopup").height())/2)
            $("#BasicPopup").css("margin-bottom",(720-$("#BasicPopup").height())/2)
    }
    function BasicConfirm(title,content,callback){
        $(".BasicPopHolder").show()
        $(".BasicPopHolder .Popup").hide()
        $("#BasicConfirm").show()
        $("#BasicConfirm").find(".PopTitle").html(title)
        $("#BasicConfirm").find(".MenuOverview").html(content)
        $("#BasicConfirm").find(".InfoButton#PopConfirm").attr("onclick",callback)
    }
    $(window).on("beforeunload", function() {
        Analytics('event', 'Game Close',{'event_category':"Page Actions","Believers": Believers})
    })
    function CloudAccess(cloudtype){
        if(kongregate){
            PlayFab.settings.titleId = "A7350";
            var loginRequest = {
                TitleId: PlayFab.settings.titleId,
                KongregateId: kongregate.services.getUserId(),
                AuthTicket: kongregate.services.getGameAuthToken(),
                CreateAccount: true
            };
            if(cloudtype=="Load"){
                PlayFabClientSDK.LoginWithKongregate(loginRequest, CloudLoad);
            }else{
                PlayFabClientSDK.LoginWithKongregate(loginRequest, CloudSave);
            }
        }
    }
    function CloudSave(result,error){
        if (result !== null) {
            PlayFabClientSDK.UpdateUserTitleDisplayName({"DisplayName": kongregate.services.getUsername()})
            //console.log("Successfully Reached Cloud Service")
            var UserD = {
                Storage: JSON.stringify(localStorage),
            }
            UserD["Backup "+(new Date()).toLocaleDateString("en-US")] = JSON.stringify(localStorage)
            PlayFabClientSDK.UpdateUserData( {Data : UserD}, function (response, error) {
                if(error) {
                    console.log("Got error setting user data");
                    console.log(error.GenerateErrorReport());
                } else{
                    console.log("Successfully updated cloud data");
                    BasicCloudLogin()
                } 
            });
        } else if (error !== null) {
            console.log("Something went wrong with your cloudsave\n" +
                "Here's some debug information:\n" +
                PlayFab.GenerateErrorReport(error))
        }
    }
    function CloudLoad(){
        PlayFabClientSDK.GetUserData({"Keys": ["Storage"]}, 
                function(result,error){
                    if (error !== null) {
                        console.log("Something went wrong with your cloudload\n" +
                            "Here's some debug information:\n" +
                            PlayFab.GenerateErrorReport(error))
                    } else if (result !== null) {
                        PlayFabData = JSON.parse(result.data.Data.Storage.Value)
                        console.log(PlayFabData)
                        clearInterval(Save)
                        //localStorage = PlayFabData
                        for(var CloudItem in PlayFabData){
                            localStorage[CloudItem] = PlayFabData[CloudItem]
                        }
                        LoadData()
                        Save = setInterval(SaveData,2000)
                    }
                })
    }
/*--------------Slot Mechanics---------------*/
    var count = 0;
    var SlotPics = {
        1: "bell",
        2: "hat",
        3: "flake",
        4: "dreidel",
        5: "present",
        6: "ornaments",
        7: "wreath",
        8: "wild"
    }
    var SpinResult = {
        1: 0,
        2: 0,
        3: 0,
        4: 0,
        5: 0
    }
    var mCasino1
    var Reels = {
        1: '',
        2: '',
        3: '',
        4: '',
        5: ''
    }
    var Machines = {
        1: '',
        2: '',
        3: '',
        4: '',
        5: ''
    }
    function SlotsInit(){
        for(var i = 1; i<=5;i++){
            Reels[i] = document.querySelector('#casino'+i);
            Machines[i] = new SlotMachine(Reels[i], {
                active: i-1,
                delay: 750
            });
        }  
    }
    function Shuffle(){
        var MachinesStopped = !Machines[1].running&&!Machines[2].running&&!Machines[3].running&&!Machines[4].running&&!Machines[5].running
        if(MachinesStopped||AutoOn=="yes"){
            count = 5;
            SpinNum += 1
            for(var i = 1; i<=5;i++){
                Machines[i].shuffle(9999)
                SpinResult[i] = 0
            }
            $(".Reward").hide()
            $(".LineLeft").css("stroke","url(#linear0)")
            $(".LineRight").css("stroke","url(#linear0)")
            for(var row = 1; row<=3;row++){
                $("#Line" + (Number(row))).css("background", Coloring(0))
            }
            $("#SpinReels").prop("disabled",true)
            if(AutoOn=="no"||AutoStopUnlocked=="no"){
                $("#StopAll").prop("disabled",false)
            }
        }else{
            console.log("Machine is Still Running")
        }
    }
    function StopReel(){
        if(count>0){
            Machines[6-count].stop();
            var SlotArray = []
            for(var i = 1;i<=3;i++){
                SlotArray.push(SlotPics[Number(Reels[6-count].querySelectorAll(".slot")[Machines[6-count].active+i].id)])
            }
            SpinResult[6-count] = SlotArray
        }
        if(count==1){
            ProcessSpin()
            if(AutoOn=="no"||AutoSpinUnlocked=="no"){
                $("#SpinReels").prop("disabled",false)
            }
        }
        count--;
    }
    function Coloring(cScore) {
        var ColorScore = (cScore / 5) * 100
        /*if(ColorScore<80&&cScore>0){
            ColorScore -= 1/(cScore)
        }*/
        switch(ColorScore){
            case 20:
                ColorScore = 18.5
                break;
            case 40:
                ColorScore = 39.2
                break;
            case 60:
                ColorScore = 59.7
                break;
            case 80:
                ColorScore = 80.13
        }
        var Background = "linear-gradient(to right, rgba(0,255,0,1) 0%, rgba(0,255,0,1) " + ColorScore + "%,#CF5178 " + ColorScore + "%,#CF5178 100%)"
        return Background
    }
    function ProcessSpin(){
        //console.log("---Processing Spin---")
        var TotalSpinScore = 0
        for(var row = 1;row<=VisibleLines;row++){
            var RowData = []
            var Score = 0
            var cScore
            if(row<=3){
                for(var column=1;column<=5;column++){
                    RowData.push(SpinResult[column][row-1])
                }
            }else if(row==4){
                RowData = [
                    SpinResult[1][2],
                    SpinResult[2][1],
                    SpinResult[3][0],
                    SpinResult[4][1],
                    SpinResult[5][2]
                ]
            }else if(row==5){
                RowData = [
                    SpinResult[1][0],
                    SpinResult[2][1],
                    SpinResult[3][2],
                    SpinResult[4][1],
                    SpinResult[5][0]
                ]
            }
            var TwoKind = RowData[0] === RowData[1] || RowData[0] === 'wild' || RowData[1] === 'wild'
            var ThreeKind = TwoKind && (RowData[2] === RowData[0] || RowData[2] === RowData[1] || RowData[2] === 'wild' || (RowData[0] === RowData[1] && RowData[0] === 'wild'))
            var FourKind = ThreeKind && (RowData[3] === RowData[0] || RowData[3] === RowData[1] || RowData[3] === RowData[2] || RowData[3] === 'wild'|| (RowData[0] === 'wild'&& RowData[1] === 'wild'&& RowData[2] === 'wild'))
            var FiveKind = FourKind && (RowData[4] === RowData[0] || RowData[4] === RowData[1] || RowData[4] === RowData[2] || RowData[4] === RowData[3] || RowData[4] === 'wild'||(RowData[0] === 'wild'&& RowData[1] === 'wild' && RowData[2] === 'wild' && RowData[3] === 'wild'))
            var AnyWin = TwoKind || ThreeKind || FourKind || FiveKind
            var ResultType = ""
            if (FiveKind) {
                ResultType = "Five of a Kind"
                Score = 150
                cScore = 5
            } else if (FourKind) {
                ResultType = "Four of a Kind"
                Score = 25
                cScore = 4
            } else if (ThreeKind) {
                ResultType = "Three of a Kind"
                Score = 5
                cScore = 3
            } else if (TwoKind) {
                ResultType = "Two of a Kind"
                Score = 1
                cScore = 2
            } else {
                Score = 0
                cScore = 0
            }
            Score = Math.round(Score*TotalMulti())
            TotalSpinScore += Score

            var ScoreText = ""
            if (Score > 0) {
                $("#Line" + (Number(row)) + " .Reward").show()
                ScoreText = "+" + DisplayLarge(Score)
            }
            $("#Line" + (Number(row)) + " .Reward").html(ScoreText)
            
            if(row<=3){
                $("#Line" + (Number(row))).css("background", Coloring(cScore))
            }else{
                var RightID
                var LeftID
                switch(cScore){
                    case 0:
                        LeftID = "0"
                        RightID = "0"
                        //$("#Line" + (Number(row)) + " .LineLeft").css("stroke","url(#linear"+LeftID+")")
                        //$("#Line" + (Number(row)) + " .LineRight").css("stroke","url(#linear"+RightID+")")
                        break;
                    case 1:
                        LeftID = "2"
                        RightID = "0"
                        break;
                    case 2:
                        LeftID = "4"
                        RightID = "0"
                        //$("#Line" + (Number(row)) + " .LineLeft").css("stroke","url(#linear"+LeftID+")")
                        //$("#Line" + (Number(row)) + " .LineRight").css("stroke","url(#linear"+RightID+")")
                        break;
                    case 3:
                        LeftID = "5"
                        RightID = "1"
                        //$("#Line" + (Number(row)) + " .LineLeft").css("stroke","url(#linear"+LeftID+")")
                        //$("#Line" + (Number(row)) + " .LineRight").css("stroke","url(#linear"+RightID+")")
                        break;
                    case 4:
                        LeftID = "5"
                        RightID = "3"
                        //$("#Line" + (Number(row)) + " .LineLeft").css("stroke","url(#linear"+LeftID+")")
                        //$("#Line" + (Number(row)) + " .LineRight").css("stroke","url(#linear"+RightID+")")
                        break;
                    case 5:
                        LeftID = "5"
                        RightID = "5"
                        //$("#Line" + (Number(row)) + " .LineLeft").css("stroke","url(#linear"+LeftID+")")
                        //$("#Line" + (Number(row)) + " .LineRight").css("stroke","url(#linear"+RightID+")")
                        break;
                }
                $("#Line" + (Number(row)) + " .LineLeft").css("stroke","url(#linear"+LeftID+")")
                $("#Line" + (Number(row)) + " .LineRight").css("stroke","url(#linear"+RightID+")")
            }
            //Achievements
                if(FiveKind&&ACHvars.JackPot==0){ACHvars.JackPot+=1}
                ACHvars.Bells += RowData.filter(x => x=="bell").length
                if(AnyWin&ACHvars.Varied<8){
                    ACHvars.vCounts[RowData[0]] = 1
                    ACHvars.vCounts[RowData[1]] = 1
                }
            //console.log("Line"+row+": "+ResultType)
        }
        ProcessScore(TotalSpinScore)
        if(TotalSpinScore==0){
            ACHvars.Fails += 1
        }
        //console.log(TotalSpinScore)
        //UpgradeCheck()
    }
    var CheckSpin
/*--------------Gameplay---------------*/
    /*------Gameplay Variables-------*/
        var TotalScore = 0
        var LifetimeScore = 0

        /*--Donation Variables--*/
            var DonationMulti = 1
            var DonationBelMulti = 1

        /*--Basic Variables--*/
            var BasicMultiplier = 1
            var StopAllUnlocked = "no"
            var AutoSpinUnlocked = "no"
            var AutoStopUnlocked = "no"
            var AutoOn = "no"
            var AutoStopSpeed = 1000

            var BaseCosts = {
                "Doubler": 1,
                "StoppingSpeed": 100
            }

        /*--Believer Variables--*/
            var Believers = 0
            var LifetimeBelievers = 0
            var BelieverLimit = 7.53e9

            var VisibleLines = 3
            var BelieverMulti = 1
            var FlakeIsWild = "no"

            var BaseLCosts = {
                "Tripler": 5,
                "MoreLines": 10,
                "ChangeFlake": 1000
            }

        /*--ToyStore Variables--*/
            var Stores = 0
            var Income = 0
            var Money = 0
            var Earning
            var IncomeInterval = 1000
        
            var sMultiplier = 1
        
            var ExtraIncome = 0
        
            var BaseSCosts = {
                MoneyPoints: .1
            }

    /*------Gameplay Basics-------*/
        var ItemID
        var StopNum    
        function GameHooks(){
            $("#SpinReels").on('click', function() {
                Shuffle()
                ACHvars.Actives += 1
            })
            $("#StopOne").on('click', function() {
                StopReel()
            })
            $("#StopAll").on('click', function() {
                StopNum = SpinNum
                for(var Reel=1;Reel<=5;Reel++){
                    setTimeout(function(){
                        if(StopNum==SpinNum){
                            StopReel()
                        }
                    },200*Reel)
                }
            })
            $("#AutoSpinCheck").on('click', function() {
                if ($("#AutoSpinCheck").prop("checked") == true) {
                    AutoOn = "yes"
                    var MachinesStopped = !Machines[1].running&&!Machines[2].running&&!Machines[3].running&&!Machines[4].running&&!Machines[5].running
                    if(MachinesStopped){
                        AutoSpinTimer = setTimeout(function(){
                            Shuffle()
                            if(AutoStopUnlocked=="yes"){
                                AutoStopTimer = setTimeout(function(){
                                    for(var Reel=1;Reel<=5;Reel++){
                                        AutoStopInterval = setTimeout(StopReel,AutoStopSpeed*Reel)
                                    }
                                },AutoStopSpeed)
                                $("#StopAll").prop("disabled",true)
                            }else{
                                $("#StopAll").prop("disabled",false)
                            }
                        },750)
                    }else{
                        if(AutoStopUnlocked=="yes"){
                            AutoStopTimer = setTimeout(function(){
                                for(var Reel=1;Reel<=5;Reel++){
                                    AutoStopInterval = setTimeout(StopReel,AutoStopSpeed*Reel)
                                }
                            },AutoStopSpeed)
                            $("#StopAll").prop("disabled",true)
                        }
                    }
                } else {
                    AutoOn = "no"
                    if(ACHvars.AutoSwitch=="no"){ACHvars.AutoSwitch="yes"}
                    $("#StopAll").prop("disabled",false)
                    clearInterval(AutoStopInterval)
                }
            })
            $("#ASCtext").on('click', function() {
                $("#AutoScratchCheck").click()
            })
            $("#WorkshopPopup .Upgrade").on('click', function() {
                Upgrade($(this).attr("id"),false)
            })
            $("#WorkshopPopup .Upgrade").on("mousedown",function(){
                ItemID = ".Upgrade#"+$(this).attr("id")
                var uGroup = "Upgrades"
                Analytics('event', 'Hold Upgrade', {'event_category':uGroup, "event_label":$(this).attr("id")})
                HUtimeout = setTimeout(function(){
                    clearInterval(HUinterval)
                    HUinterval= setInterval(function(){
                        if($(ItemID).is(":active")&&!$(ItemID).prop("disabled")&&$(ItemID).is(":visible")){
                            Upgrade($(ItemID).attr("id"),true)
                        }else{
                            clearInterval(HUinterval)
                            return
                        }
                    },60)
                },600)
            })
            $("#SleighPopup .Upgrade").on('click', function() {
                BelieverUpgrade($(ItemID).attr("id"),false)
            })
            $("#SleighPopup .Upgrade").on("mousedown",function(){
                ItemID = ".Upgrade#"+$(this).attr("id")
                var uGroup = "Believer"
                Analytics('event', 'Hold Upgrade', {'event_category':uGroup, "event_label":$(this).attr("id")})
                HUtimeout = setTimeout(function(){
                    clearInterval(HUinterval)
                    HUinterval= setInterval(function(){
                        if($(ItemID).is(":active")&&!$(ItemID).prop("disabled")&&$(ItemID).is(":visible")){
                            BelieverUpgrade($(ItemID).attr("id"),true)
                        }else{
                            clearInterval(HUinterval)
                            return
                        }
                    },60)
                },600)
            })
            $(".Prestige#Prestige").on('click', function() {
                var BelieversAvailable = BelieversAvailableNow()
                if(BelieverAlert=="On"){
                    BasicConfirm("Prestige",'Are you sure you would like to<br>deliver gifts to get ' + DisplayLarge(BelieversAvailable) + " Believers<br><br>This popup can be disabled in settings","Prestige()")
                }else{
                    Prestige()
                }
            })
            $(".InfoButton#BelieverAlerts").on('click', function() {
                if(BelieverAlert=="On"){
                    BelieverAlert = "Off"
                }else{
                    BelieverAlert = "On"
                }
                $("#BelieverAlert").html(BelieverAlert)
            })
            $(".BuyStoreButton").on('click', function() {
                var StoreAvailable = (Believers>=7.53e9)
                var AvailableStores = "1 Toy Store"
                if(hUpgrades.MultiStores=="yes"){
                    var CurrentStoresAvailable = Math.max(0,Math.floor(Math.log(Believers)/Math.log(7.53e9)))
                    if(CurrentStoresAvailable>1&&CurrentStoresAvailable<=5){
                        AvailableStores = CurrentStoresAvailable+" Toy Stores"
                    }
                }
                if(StoreAvailable){
                    if(StoreAlert=="On"){
                        BasicConfirm("Buy Store",'Are you sure you would like to buy<br>'+AvailableStores+' and reset upgrades and points?<br><br>This popup can be disabled in settings',"BuyStore()")
                    }else{
                        BuyStore()
                    }
                }
            })
            $("#ToyStorePopup .Upgrade").on('click', function() {
                StorePurchase($(this).attr("id"))
            })
            $(".InfoButton#StoreAlerts").on('click', function() {
                if(StoreAlert=="On"){
                    StoreAlert = "Off"
                }else{
                    StoreAlert = "On"
                }
                $("#StoreAlert").html(StoreAlert)
            })
            $(".BuyCompanyButton").on('click', function() {
                CompanyAvailable = (Stores>=StoreThresh)
                if(CompanyAvailable){
                    if(CompAlert=="On"){
                        BasicConfirm("Convert",'Are you sure you would like to give up your stores and reset for 1 powerful Hanukkah point<br><br>This popup can be disabled in settings',"MakeCompany()")
                    }else{
                        MakeCompany()
                    }
                    /*WillCompany = confirm('Are you sure you would like to consolidate your stores and reset for 1 powerful corporate point')
                    if (WillCompany) {
                        MakeCompany()
                    }*/
                }
            })
            $(".CompanyUpgrade").on('click', function() {
                CompanyUpgrade($(this).attr("id"))
            })
            $(".InfoButton#CompAlerts").on('click', function() {
                if(CompAlert=="On"){
                    CompAlert = "Off"
                }else{
                    CompAlert = "On"
                }
                $("#CompAlert").html(CompAlert)
            })
            $("#AutoStoreCheck").on('click', function() {
                if ($("#AutoStoreCheck").prop("checked") == true) {
                    hUpgrades.AutoStoreOn = "yes"
                    StoreCheck()
                }else{
                    hUpgrades.AutoStoreOn = "no"
                }
            })
            $("#AutoStoreAMT").on('change', function() {
                hUpgrades.AutoStoreAMT = Number($("#AutoStoreAMT").val())
            })
            $("#AutoCompCheck").on('click', function() {
                if ($("#AutoCompCheck").prop("checked") == true) {
                    NYUpgrades.AutoCompanyOn = "yes"
                    CompanyCheck()
                }else{
                    NYUpgrades.AutoCompanyOn = "no"
                }
            })
            $("#AutoCompAMT").on('change', function() {
                NYUpgrades.AutoCompanyAMT = Number($("#AutoCompAMT").val())
            })
            $(".Donation").on('click', function() {
                dType = $(this).attr('id')
                //store.order(dType);
                if(kongregate){kongregate.mtx.purchaseItems([dType], function(result){
                    onPurchaseResult(result.success,dType)
                })}
                Analytics('event', 'Attempt',{'event_category':"Donations",'event_label': dType})
            })
            EmpireHooks()
        }
        
    /*------Storage-------*/
        var BaseCamp
        var Belgrade
        var Storeage
        var Archiver
        var Core
        var Extras
        function SaveData(){
            //Basic Variables
                BaseCamp = {
                    "TotalScore": TotalScore,
                    "LifetimeScore": LifetimeScore,
                    "BasicMultiplier": BasicMultiplier,
                    "StopAllUnlocked": StopAllUnlocked,
                    "AutoSpinUnlocked": AutoSpinUnlocked,
                    "AutoStopUnlocked": AutoStopUnlocked,
                    "AutoOn": AutoOn,
                    "AutoStopSpeed": AutoStopSpeed,
                    "Costs": {}
                }
                    $(".UpgradeHolder").each(function() {
                        var uCost = $(this).find(".Cost").html()
                        var uName = $(this).attr("id")
                        BaseCamp.Costs[uName] = uCost
                    })
            //Believer Variables
                Belgrade = {
                    "Believers": Believers,
                    "LifetimeBelievers": LifetimeBelievers,
                    "BelieverLimit": BelieverLimit,
                    "VisibleLines": VisibleLines,
                    "BelieverMulti": BelieverMulti,
                    "FlakeIsWild": FlakeIsWild,
                    "Costs": {}
                }
                    $(".BelUpgradeHolder").each(function() {
                        var uCost = $(this).find(".Cost").html()
                        var uName = $(this).attr("id")
                        Belgrade.Costs[uName] = uCost
                    })
            //Store Variables
                Storeage = {
                    "Stores": Stores,
                    "Income": Income,
                    "Money": Money,
                    "sMultiplier": sMultiplier,
                    "Automators": Automators,
                    "Costs": {}
                }
                    $(".StoreHolder#MoneyPoints").each(function() {
                        var uCost = $(this).find(".Cost").html()
                        var uName = $(this).attr("id")
                        Storeage.Costs[uName] = uCost
                    })
            //Hanukkah Variables
                Core = {
                    "Companies": Companies,
                    "LifetimeCompanies": LifetimeCompanies,
                    "HPoints": HPoints,
                    "StoreThresh": StoreThresh,
                    "cMultiplier": cMultiplier,
                    "hUpgrades": hUpgrades,
                    "Costs": {}
                }
                    $(".CompanyHolder").each(function() {
                        var uCost = $(this).find(".Cost").html()
                        var uName = $(this).attr("id")
                        Core.Costs[uName] = uCost
                    })
            //New Year Variables
                Extras = {
                    "EmpireComps": EmpireComps,
                    "LifetimeMonths": LifetimeMonths,
                    "Months": Months,
                    "TotalMonths": TotalMonths,
                    "NYPrestiges": NYPrestiges,
                    "NYUpgrades": NYUpgrades,
                    "NGMulti": NGMulti,
                    "NGamt": NGamt,
                    "Costs": {}
                }
                    $(".EmpireHolder").each(function() {
                        var uCost = $(this).find(".Cost").html()
                        var uName = $(this).attr("id")
                        Extras.Costs[uName] = uCost
                    })
            //Achievements
                Archiver = {
                    "ACHcount": ACHcount,
                    "ACHmulti": ACHmulti,
                    "ACHchange": ACHchange,
                    "Achievements": Achievements,
                    "ACHvars": ACHvars,
                }
            //Settings
                Sett = {
                    "NumberSystem": NumberSystem,
                    "BelieverAlert": BelieverAlert,
                    "StoreAlert": StoreAlert,
                    "CompAlert": CompAlert
                }
            //Store Variables
                localStorage.BaseCamp = btoa(JSON.stringify(BaseCamp))
                localStorage.Belgrade = btoa(JSON.stringify(Belgrade))
                localStorage.Storeage = btoa(JSON.stringify(Storeage))
                localStorage.Core = btoa(JSON.stringify(Core))
                localStorage.Extras = btoa(JSON.stringify(Extras))
                localStorage.Archiver = btoa(JSON.stringify(Archiver))
                localStorage.Sett = btoa(JSON.stringify(Sett))
                localStorage.STT = btoa(Number(new Date()))
                localStorage.BPShown = BPShown
        }
        function LoadData(){
            //Load Basics
                if(localStorage.BaseCamp){
                    var BasicUpgrades = JSON.parse(atob(localStorage.BaseCamp))
                    TotalScore = Number(BasicUpgrades.TotalScore)
                    LifetimeScore = Number(BasicUpgrades.LifetimeScore)
                    BasicMultiplier = Number(BasicUpgrades.BasicMultiplier)
                    StopAllUnlocked = BasicUpgrades.StopAllUnlocked
                    AutoSpinUnlocked = BasicUpgrades.AutoSpinUnlocked
                    AutoStopUnlocked = BasicUpgrades.AutoStopUnlocked
                    AutoOn = BasicUpgrades.AutoOn
                    AutoStopSpeed = Number(BasicUpgrades.AutoStopSpeed)
                    for(var anUpgrade in BasicUpgrades.Costs){
                        var uID = anUpgrade
                        var uCost = ReadLarge(BasicUpgrades.Costs[anUpgrade])
                        $(".UpgradeHolder#"+uID).find(".Cost").html(DisplayLarge(uCost))
                    }
                }
            //Load Believers
                if(localStorage.Belgrade){
                    var BelieverUpgrades = JSON.parse(atob(localStorage.Belgrade))
                    Believers = Number(BelieverUpgrades.Believers)
                    LifetimeBelievers = Number(BelieverUpgrades.LifetimeBelievers)
                    BelieverLimit = Number(BelieverUpgrades.BelieverLimit)
                    VisibleLines = Number(BelieverUpgrades.VisibleLines)
                    BelieverMulti = Number(BelieverUpgrades.BelieverMulti)
                    FlakeIsWild = BelieverUpgrades.FlakeIsWild
                    for(var anUpgrade in BelieverUpgrades.Costs){
                        var uID = anUpgrade
                        var uCost = ReadLarge(BelieverUpgrades.Costs[anUpgrade])
                        $(".BelUpgradeHolder#"+uID).find(".Cost").html(DisplayLarge(uCost))
                    }
                }
                if(localStorage.BPShown){
                    BPShown = Boolean(localStorage.BPShown)
                }
            //Load Store
                if(localStorage.Storeage){
                    var StoreData = JSON.parse(atob(localStorage.Storeage))
                    Stores = Number(StoreData.Stores)
                    Income = Number(StoreData.Income)
                    Money = Number(StoreData.Money)
                    sMultiplier = Number(StoreData.sMultiplier)
                    Automators = StoreData.Automators
                    for(var anUpgrade in StoreData.Costs){
                        var uID = anUpgrade
                        var uCost = ReadLarge(StoreData.Costs[anUpgrade])
                        if(uCost<1000){
                            $(".StoreHolder#"+uID).find(".Cost").html(uCost.toFixed(2))
                        }else{
                            $(".StoreHolder#"+uID).find(".Cost").html(DisplayLarge(uCost))
                        }
                    }
                }
            //Load Hanukkah
                if(localStorage.Core){
                    var CompanyData = JSON.parse(atob(localStorage.Core))
                    Companies = Number(CompanyData.Companies)
                    LifetimeCompanies = Number(CompanyData.LifetimeCompanies)
                    HPoints = Number(CompanyData.HPoints)
                    StoreThresh = Number(CompanyData.StoreThresh)
                    cMultiplier = Number(CompanyData.cMultiplier)
                    hUpgrades = CompanyData.hUpgrades
                    for(var anUpgrade in CompanyData.Costs){
                        var uID = anUpgrade
                        var uCost = ReadLarge(CompanyData.Costs[anUpgrade])
                        var WrittenCost = Number($(".CompanyHolder#"+uID).find(".Cost").html())
                        if(uCost!=WrittenCost&&uID!="CompanyPoints"){
                            if(uCost>WrittenCost&&hUpgrades[uID] == "yes"){
                                HPoints += (uCost-WrittenCost)
                            }else if(uCost<WrittenCost&&hUpgrades[uID] == "yes"){
                                HPoints += uCost
                                hUpgrades[uID] = "no"
                            }
                            uCost = WrittenCost
                        }
                        $(".CompanyHolder#"+uID).find(".Cost").html(DisplayLarge(uCost))
                    }
                }
            //Load New Year
                if(localStorage.Extras){
                    var NYData = JSON.parse(atob(localStorage.Extras))
                    EmpireComps = Number(NYData.EmpireComps)
                    LifetimeMonths = Number(NYData.LifetimeMonths)
                    Months = Number(NYData.Months)
                    TotalMonths = Number(NYData.TotalMonths)
                    NYPrestiges = Number(NYData.NYPrestiges)
                    NYUpgrades = NYData.NYUpgrades
                    NGMulti = Number(NYData.NGMulti)
                    NGamt = Number(NYData.NGamt)
                    for(var anUpgrade in NYData.Costs){
                        var uID = anUpgrade
                        var uCost = ReadLarge(NYData.Costs[anUpgrade])
                        $(".EmpireHolder#"+uID).find(".Cost").html(DisplayLarge(uCost))
                    }
                }
            //Load Achievements
                if(localStorage.Archiver){
                    var ACHdata = JSON.parse(atob(localStorage.Archiver))
                    ACHcount = ACHdata.ACHcount
                    ACHmulti = ACHdata.ACHmulti
                    ACHchange = ACHdata.ACHchange
                    for(var Ach in ACHdata.Achievements){
                        Achievements[Ach] = ACHdata.Achievements[Ach]
                    }
                    for(var aVar in ACHdata.ACHvars){
                        ACHvars[aVar] = ACHdata.ACHvars[aVar]
                    }
                }
            //Settings
                if(localStorage.Sett){
                    var StoredSettings = JSON.parse(atob(localStorage.Sett))
                    NumberSystem = StoredSettings.NumberSystem,
                    BelieverAlert = StoredSettings.BelieverAlert,
                    StoreAlert = StoredSettings.StoreAlert,
                    CompAlert = StoredSettings.CompAlert
                }
            //Offline Income
                var NewMoney = 0
                if(localStorage.STT){
                    Offline = Math.round((Number(new Date()) - Number(atob(localStorage.STT)))/60000)
                    NewMoney = Number(((Income*Offline)).toFixed(2))
                    var DisplayTime = (Offline/60).toFixed(1) + " Hours"
                    if((Offline/60)<1){
                        DisplayTime = Offline.toFixed(0) + " Minutes"
                    }else if((Offline/60)>24){
                        DisplayTime = (Offline/(24*60)).toFixed(1) + " Days"
                    }
                    Money += NewMoney
                    BasicPopup("Offline Progress","Welcome Back!<br><br>You were offline for "+DisplayTime+". You earned 100% of your Store Income and gained: $"+NewMoney.toFixed(2))
                }
            //New Player Check
                if(!localStorage.BaseCamp){
                    BasicPopup("Welcome!","I hope you like this holiday ‘spin off’ of my previous game!<br><br>This version adds a few new upgrades and new mechanisms like Prestige Multi-Buy and New Game+.<br><br>Please let me know in the forums/comments if you run into any bugs or want any other features, and have a great holiday season!!<br><br>-Makopaz-")
                    Analytics('event', 'New Player', {'event_category':"Page Actions" })
                }
            //Show Lines
                for(var Line=1;Line<=5;Line++){
                    if(Line<=VisibleLines){
                        $("#Line"+Line).show()
                    }else{
                        $("#Line"+Line).hide()
                    }
                }
            //Fixes
                if(hUpgrades.PermaAutoUpgrades=="yes"&&hUpgrades.PermaBuyers.GetStopAll=="no"){
                    hUpgrades.PermaBuyers['GetStopAll']="yes"
                    $(".StoreHolder#"+'aGetStopAll').find(".Upgrade").prop("disabled",true)
                    $(".StoreHolder#"+'aGetStopAll').find(".Upgrade").css("background-color","rgb(53, 79, 58)")
                    $(".StoreHolder#"+'aGetStopAll').find(".HireFire").html("Fire")
                    Automators["auto"+'aGetStopAll'.substr(1)] = "yes"
                }
            FixNumbers()
            IncomeCheck()
            LoadStore()
            AchievementInit()
            AllChecks()
            $("#NumberType").html(NumberSystem)
            $("#StoreAlert").html(StoreAlert)
            $("#BelieverAlert").html(BelieverAlert)
            $("#CompAlert").html(CompAlert)
            ShowBenefits()
            AutoSpinChecker()
        }
    /*------Results-------*/
        function TotalMulti(){
            TotMult = 1
            TotMult = BasicMultiplier * DonationMulti * BelieverMulti * sMultiplier * cMultiplier /* NGMulti*/ * ACHmulti
            return TotMult
        }
        function ShowBenefits(){
            //Basic Vars
                $(".TotalAMT").each(function(){
                    $(this).html(DisplayLarge(TotalScore))
                })
                $(".Believers").each(function(){
                    $(this).html(DisplayLarge(Believers))
                })
            //Basic Mutli
                $("#BasicMulti").html(DisplayLarge(BasicMultiplier))
            //Believer Multi
                $("#BelMulti").html(DisplayLarge(BelieverMulti))
            //Store Indicators
                $("#sMulti").html(DisplayLarge(sMultiplier))
            //Company Indicators
                $("#cMulti").html(DisplayLarge(cMultiplier))
            //Empire Indicators
                $("#IncomeMulti").html(DisplayLarge(NYUpgrades.EmpireIncomeMulti))
                $("#eMulti").html(DisplayLarge(NYUpgrades.EmpireMulti))
                $("#NGMulti").html(DisplayLarge(NGMulti))
            //Show Full Multi
                $("#TotalMulti").html(DisplayLarge(TotalMulti()))
            //Show AutoCheck
                if(AutoOn=="yes"){
                    $("#AutoSpinCheck").prop("checked",true)
                }else{
                    $("#AutoSpinCheck").prop("checked",false)
                }
        }
        function AllChecks(){
            UpgradeCheck()
            BelieverCheck()
            StoreCheck()
            CompanyCheck()
            EmpireCheck()
            ShowBenefits()
            ButtonAutomation()
            AchievementCheck()
        }
        function ProcessScore(Score){
            TotalScore += Score
            LifetimeScore += Score
            $(".TotalAMT").each(function(){
                $(this).html(DisplayLarge(TotalScore))
            })
            AutoSpinChecker()
            if(Score>0&&BasicMultiplier==1&&Believers==0&&Stores==0&&LifetimeCompanies==0&&NGMulti==1){
                $("#WorkshopMenu").click()
                BasicPopup("Upgrades","You are ready for your first upgrades<br><br>Upgrades allow you to increase the number of presents you get from spins and automate the spinning process.<br><br>The North Pole icon in the bottom-left will light up when upgrades are available.")
                $("#BasicPopup").css("margin-top",((720-$("#BasicPopup").height())/2)+50)
            }
            if(hUpgrades.AutoDelivery == "yes"){
                var BelieversAvailable = BelieversAvailableNow()
                Believers += BelieversAvailable
                LifetimeBelievers += BelieversAvailable
            }
            AllChecks()
            if(kongregate){kongregate.stats.submit('Log10 Presents', Math.log10(LifetimeScore))}
        }
        function AutoSpinChecker(){
            if(AutoSpinUnlocked == "yes"){
                if(AutoOn=="yes"){
                    AutoSpinTimer = setTimeout(function(){
                        Shuffle()
                        if(AutoStopUnlocked=="yes"){
                            AutoStopTimer = setTimeout(function(){
                                StopNum = SpinNum
                                for(var Reel=1;Reel<=5;Reel++){
                                    AutoStopInterval = setTimeout(function(){
                                            if(StopNum==SpinNum){
                                                StopReel()
                                            }
                                        },AutoStopSpeed*Reel)
                                }
                            },AutoStopSpeed)
                            $("#StopAll").prop("disabled",true)
                        }else{
                            $("#StopAll").prop("disabled",false)
                        }
                    },750)
                }else{
                    $("#StopAll").prop("disabled",false)
                }
            }
        }
    /*------Basic Upgrading-------*/
        function UpgradeCheck(){
            var UpgradesAvailable = false
            $(".UpgradeHolder").each(function() {
                var TheCost = ReadLarge($(this).find(".Cost").html())
                if(!$(this).hasClass("Wait") && !$(this).hasClass("OneTime")){
                    if(TotalScore>=TheCost&&TheCost<Infinity){
                        $(this).find(".Upgrade").prop("disabled",false)
                        UpgradesAvailable = true
                    }else{
                        $(this).find(".Upgrade").prop("disabled",true)
                    }
                }else{
                    switch($(this).attr("id")){
                        case "GetStopAll":
                            if(TotalScore>=TheCost && StopAllUnlocked == "no"){
                                $(this).find(".Upgrade").prop("disabled",false)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $("#StopAll").hide()
                                $("#StopAllBreak").show()
                                UpgradesAvailable = true
                            }else if(StopAllUnlocked == "no"){
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $("#StopAll").hide()
                                $("#StopAllBreak").show()
                            }else{
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).hide()
                                $(this).find(".CostLabel").hide()
                                $("#StopAll").show()
                                $("#StopAllBreak").hide()
                            }
                            break;
                        case "AutoSpin":
                            if(TotalScore>=TheCost && AutoSpinUnlocked == "no"){
                                $(this).find(".Upgrade").prop("disabled",false)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $("#AutoSpinCheckHolder").hide()
                                $("#AutoSpinBreak").show()
                                UpgradesAvailable = true
                            }else if(AutoSpinUnlocked == "no"){
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $("#AutoSpinCheckHolder").hide()
                                $("#AutoSpinBreak").show()
                            }else{
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).hide()
                                $(this).find(".CostLabel").hide()
                                $("#AutoSpinCheckHolder").show()
                                $("#AutoSpinBreak").hide()
                            }
                            break;
                        case "AutoStop":
                            if(TotalScore>=TheCost && AutoStopUnlocked == "no" && AutoSpinUnlocked == "yes"){
                                $(this).find(".Upgrade").prop("disabled",false)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $("#AndStop").hide()
                                $("#AutoStopBreak").show()
                                UpgradesAvailable = true
                            }else if(AutoStopUnlocked == "no"){
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $("#AndStop").hide()
                                $("#AutoStopBreak").show()
                            }else{
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).hide()
                                $(this).find(".CostLabel").hide()
                                $("#AndStop").show()
                                $("#AutoStopBreak").hide()
                            }
                            break;
                        case "StoppingSpeed":
                            if(TotalScore>=TheCost && AutoStopSpeed>=200 && AutoStopUnlocked == "yes"){
                                $(this).find(".Upgrade").prop("disabled",false)
                                $(this).find(".Upgrade").html("+10% Faster<br>AutoStop")
                                $(this).find(".CostLabel").show()
                                $(this).find(".HeadsUp").hide()
                                UpgradesAvailable = true
                            }else if(AutoStopUnlocked == "yes"){
                                $(this).find(".Upgrade").prop("disabled",true)
                                if(AutoStopSpeed<200){
                                    $(this).find(".Upgrade").html("Max Speed")
                                    $(this).find(".CostLabel").hide()
                                    $(this).find(".HeadsUp").hide()
                                }else{
                                    $(this).find(".Upgrade").html("+10% Faster<br>AutoStop")
                                    $(this).find(".CostLabel").show()
                                    $(this).find(".HeadsUp").hide()
                                }
                            }else{
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).find(".Upgrade").html("+10% Faster<br>AutoStop")
                                $(this).find(".CostLabel").show()
                                $(this).find(".HeadsUp").show()
                            }
                            break;
                    }
                }
            })
            
            if(UpgradesAvailable){
                $("#WorkshopMenu").css("filter","grayscale(0)")
            }else{
                $("#WorkshopMenu").css("filter","grayscale(1)")
            }
            ShowBenefits()
        }
        function Upgrade(uType,Autoed){
            var TheCost = ReadLarge($(".UpgradeHolder#"+uType+" .Cost").html())
            //console.log(uType,TheCost)
            if(TotalScore>=TheCost && TheCost<Infinity){
                switch(uType){
                    case "Doubler":
                        TotalScore -= TheCost
                        $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                        BasicMultiplier *= 2
                        if(TheCost==1){
                            TheCost = 3
                        }else if(TheCost==3){
                            TheCost = 10
                        }else{
                            TheCost *= 3
                        }
                        $(".UpgradeHolder#"+uType+" .Cost").html(DisplayLarge(TheCost))
                        break;
                    case "GetStopAll":
                        TotalScore -= TheCost
                        $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                        StopAllUnlocked = "yes"
                        break;
                    case "AutoSpin":
                        TotalScore -= TheCost
                        $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                        AutoSpinUnlocked = "yes"
                        var WaitStart = setTimeout(function(){
                            var MachinesStopped = !Machines[1].running&&!Machines[2].running&&!Machines[3].running&&!Machines[4].running&&!Machines[5].running
                            if(MachinesStopped&&AutoOn=="yes"){
                                Shuffle()
                            }
                        },205)
                        break;
                    case "AutoStop":
                        TotalScore -= TheCost
                        $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                        AutoStopUnlocked = "yes"
                        var WaitStop = setTimeout(function(){
                            var MachinesStopped = !Machines[1].running&&!Machines[2].running&&!Machines[3].running&&!Machines[4].running&&!Machines[5].running
                            if(AutoOn=="yes"&&!MachinesStopped){
                                for(var Reel=1;Reel<=5;Reel++){
                                    if(Machines[Reel].running){
                                        StopReel()
                                    }
                                }
                            }
                        },225)
                        break;
                    case "StoppingSpeed":
                        TotalScore -= TheCost
                        $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                        AutoStopSpeed *= .90
                        TheCost = Math.floor(TheCost*1.4)
                        $(".UpgradeHolder#"+uType+" .Cost").html(DisplayLarge(TheCost))
                        break;
                    }
                }
            UpgradeCheck()
            if(!Autoed){
                AchievementCheck()
                Analytics('event', 'Upgrade', {'event_category':"Upgrades", "event_label": uType, "Price": TheCost })
            }
            }
    /*------Believers-------*/
        function BelieverCheck(){
            /*--If subtract taken--*/
                //LoyaltyPossible = Math.max(0,(100*Math.sqrt(LifetimeScore/5000))-14.14);
                //LoyaltyAvailable = Math.max(0,LoyaltyPossible-LifetimeLoyalty)
            var BelieversAvailable = BelieversAvailableNow()
            if(Believers==BelieverLimit&&BelieversAvailable==0){
                $("button.Prestige").html("Everyone<br>Believes In You")
                $("#ToUnlock").hide()
                $("#Unlocked").show()
            }else if((Believers+BelieversAvailable)>=BelieverLimit){
                $("button.Prestige").html("Get Remaining<br>Believers")
                $("#ToUnlock").show()
                $("#Unlocked").hide()
            }else{
                $("button.Prestige").html('Deliver To Get<br><span id="AvailBelievers">'+DisplayLarge(BelieversAvailable)+'</span> Believers')
                $("#ToUnlock").show()
                $("#Unlocked").hide()
            }
            $(".Believers").each(function(){
                $(this).html(DisplayLarge(Believers))
            })
            $("#AvailBelievers").html(DisplayLarge(BelieversAvailable))
            if(BelieversAvailable>=5){
                $(".Prestige#Prestige").prop("disabled",false)
            }else{
                $(".Prestige#Prestige").prop("disabled",true)
            }
            if(BelieversAvailable>=10&& !BPShown &&Believers == 0&&Stores==0&&LifetimeCompanies==0&&LifetimeMonths==0&&NGMulti==1){
                $("#SleighMenu").click()
                BasicPopup("Believers","You are ready to deliver your presents and get believers.<br><br>By delivering presents you reset your progress but can get upgrades that help you push even further toward the next stage: Toy Stores.<br><br>The sleigh in the bottom menu will light up when you are able to get upgrades by delivering.<br><br><b>Feel free to do this now, or wait longer until you have more to get!<b>")
                BPShown = true
            }
            BelieverUpgradeCheck()
        }
        var BPShown = false
        function BelieversAvailableNow(){
            var BelieversAvailable = Math.max(0,Math.floor(Math.pow(LifetimeScore/7.3,1/3)));
            BelieversAvailable *= DonationBelMulti * NYUpgrades.EmpireMulti * NGMulti
            /*--Value Switch Checks--*/
                if((BelieversAvailable+Believers)>=BelieverLimit){BelieversAvailable=(BelieverLimit-Believers)}
                if(BelieversAvailable<=2||Believers>=BelieverLimit){BelieversAvailable=0}
            return BelieversAvailable
        }
        function BelieverUpgradeCheck(){
            var BelieverUpgradesAvailable = false
            var BelieversAvailable = BelieversAvailableNow()
            $(".BelUpgradeHolder").each(function() {
                var TheCost = ReadLarge($(this).find(".Cost").html())
                if(!$(this).hasClass("Limit") && !$(this).hasClass("OneTime")){
                    if(Believers>=TheCost&&TheCost<Infinity){
                        if((BelieverLimit<1e10&&TheCost>1e9)||TheCost>=BelieverLimit){
                            $(this).find(".Upgrade").prop("disabled",true)
                            $(this).find(".Upgrade").html("Max Multi")
                            $(this).find(".CostLabel").hide()
                        }else{
                            $(this).find(".Upgrade").prop("disabled",false)
                            $(this).find(".Upgrade").html("Triple Presents")
                            $(this).find(".CostLabel").show()
                            if(Automators.autoTripler=="no"){
                                BelieverUpgradesAvailable = true
                            }
                        }
                    }else{
                        $(this).find(".Upgrade").prop("disabled",true)
                        if(BelieverLimit<1e10&&TheCost>1e9||TheCost>=BelieverLimit){
                            $(this).find(".Upgrade").html("Max Multi")
                            $(this).find(".CostLabel").hide()
                        }else{
                            $(this).find(".Upgrade").html("Triple Presents")
                            $(this).find(".CostLabel").show()
                            if((BelieversAvailable+Believers)>=TheCost){
                                if(Automators.autoTripler=="no"||hUpgrades.AutoDelivery=="no"){
                                    BelieverUpgradesAvailable = true
                                }
                            }
                        }
                    }
                }else{
                    switch($(this).attr("id")){
                        case "MoreLines":
                            if(Believers>=TheCost && VisibleLines<5){
                                $(this).find(".Upgrade").prop("disabled",false)
                                $(this).find(".CostLabel").show()
                                $(this).find(".Upgrade").html("Add Another<br>Win Line")
                                BelieverUpgradesAvailable = true
                            }else if(VisibleLines<5){
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).find(".CostLabel").show()
                                $(this).find(".Upgrade").html("Add Another<br>Win Line")
                                if((BelieversAvailable+Believers)>=TheCost){
                                    BelieverUpgradesAvailable = true
                                }
                            }else{
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).find(".CostLabel").hide()
                                $(this).find(".Upgrade").html("Max Lines")
                            }
                            for(var Line=4;Line<=5;Line++){
                                if(Line<=VisibleLines){
                                    $("#Line"+Line).show()
                                }else{
                                    $("#Line"+Line).hide()
                                }
                            }
                            break;
                        case "ChangeFlake":
                            if(Believers>=TheCost && FlakeIsWild == "no"){
                                $(this).find(".Upgrade").prop("disabled",false)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $(".formerflake").attr("class","slot slot3").attr("id","3")
                                BelieverUpgradesAvailable = true
                            }else if(FlakeIsWild == "no"){
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).show()
                                $(this).find(".CostLabel").show()
                                $(".formerflake").attr("class","slot slot3").attr("id","3")
                                if((BelieversAvailable+Believers)>=TheCost){
                                    BelieverUpgradesAvailable = true
                                }
                            }else{
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).hide()
                                $(this).find(".CostLabel").hide()
                                $(".slot3").attr("class","slot slot8 formerflake").attr("id","8")
                            }
                            break;
                    }
                }
            })
            if(Believers<BelieverLimit&&(BelieversAvailable+Believers)>=BelieverLimit){
                BelieverUpgradesAvailable = true
            }
            if(BelieverUpgradesAvailable){
                $("#SleighMenu").css("filter","grayscale(0)")
            }else{
                $("#SleighMenu").css("filter","grayscale(1)")
            }
            ShowBenefits()
        }
        function BelieverUpgrade(uType,Autoed){
            var ReachedLimit = Believers>=BelieverLimit
            var TheCost = ReadLarge($(".BelUpgradeHolder#"+uType+" .Cost").html())
            if(Believers>=TheCost && TheCost<Infinity){
                switch(uType){
                    case "Tripler":
                        Believers -= TheCost
                        $(".Believers").each(function(){
                            $(this).html(DisplayLarge(Believers))
                        })
                        BelieverMulti *= 3
                        TheCost *= 3
                        $(".BelUpgradeHolder#"+uType+" .Cost").html(DisplayLarge(TheCost))
                        break;
                    case "MoreLines":
                        Believers -= TheCost
                        $(".Believers").each(function(){
                            $(this).html(DisplayLarge(Believers))
                        })
                        VisibleLines += 1
                        TheCost *= 25
                        $(".BelUpgradeHolder#"+uType+" .Cost").html(DisplayLarge(TheCost))
                        break;
                    case "ChangeFlake":
                        Believers -= TheCost
                        $(".Believers").each(function(){
                            $(this).html(DisplayLarge(Believers))
                        })
                        FlakeIsWild = "yes"
                        break;
                    }
                }
            if(ReachedLimit){
                Believers = BelieverLimit
            }
            BelieverCheck()
            if(!Autoed){
                AchievementCheck()
                Analytics('event', 'Upgrade', {'event_category':"Believers", "event_label": uType, "Price": TheCost })
            }
        }
        function Prestige(){
            /*--Give Loyalty--*/
                var BelieversAvailable = BelieversAvailableNow()
                Believers += Math.round(BelieversAvailable)
                LifetimeBelievers += BelieversAvailable
            /*--Reset Automation Variables--*/
                if(NYUpgrades.RetainAutomation=="no"){
                    AutoSpinUnlocked = "no"
                    AutoStopUnlocked = "no"
                    AutoStopSpeed = 1000
                    /*--Stop Reels--*/
                        for(var ReelStop = 1;ReelStop<=5;ReelStop++){
                            Machines[ReelStop].stop()
                        }
                        $("#SpinReels").prop("disabled",false)
                }
            /*--Reset Basic Variables--*/
                TotalScore = 0
                LifetimeScore = 0
                BasicMultiplier = 1
                StopAllUnlocked = "no"
            /*--Reset Costs--*/
                for(var RegUp in BaseCosts){
                    $(".UpgradeHolder#"+RegUp).find(".Cost").html(DisplayLarge(BaseCosts[RegUp]))
                }
            /*--Display Variables--*/
                $("#AvailBelievers").html(0)
                $(".Believers").each(function(){
                    $(this).html(DisplayLarge(Believers))
                })
                $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
            /*--Save Variables--*/
                SaveData()
            /*--Check Updates--*/
                AllChecks()
            /*--Auto Upgrades--*/
                //AutoBuy("autoMoreIcons")
                //AutoBuy("autoTripler")
                /*if(Automators["autoAutomation"]=="yes"){
                    TotalScore += 25
                    if(Automators["autosSpeed"]=="yes"){
                        ScratchAutoSpeed = 2
                    }
                    if(Automators["autoSpeedEff"]=="yes"){
                        AutoQuick = 4
                    }
                    Upgrade("Automation",true)
                }*/
            /*Help New Players*/
                if(Believers >= 7.53e9 && Stores == 0 && Companies == 0){
                    var FirstStore = setTimeout(function(){
                        $("#ToyStoreMenu").click()
                        BasicPopup("Stores","Everyone on Earth is a believer now, you are now ready for the next level of prestige, toy store ownership awaits you.")
                    },500)
                    //console.log("hi")
                }
            /*--Log Prestige--*/
                Analytics('event', 'Believers', {'event_category':"Prestige", "BelieversEarned": BelieversAvailable, "CurrentBelievers": Believers })
                //if(kongregate){kongregate.stats.submit('Deliveries', 1)}
        }
    /*------Store Prestige-------*/
    
        function StoreCheck(){
            var StoreAvailable = (Believers>=7.53e9)
            if(StoreAvailable){
                $(".BuyStoreButton").prop("disabled",false)
                $(".BuyStoreButton img").css("filter","grayscale(0)")
                //$("#StoreMenu").css("filter","grayscale(0)")
            }else{
                $(".BuyStoreButton").prop("disabled",true)
                $(".BuyStoreButton img").css("filter","grayscale(1)")
                /*if(Stores==0){
                    $("#StoreMenu").css("filter","grayscale(1)")
                }else{
                    $("#StoreMenu").css("filter","grayscale(0)")
                }*/
            }
            if(hUpgrades.MultiStores=="yes"){
                var CurrentStoresAvailable = Math.max(0,Math.floor(Math.log(Believers)/Math.log(7.53e9)))
                if(CurrentStoresAvailable>0&&CurrentStoresAvailable<=5){
                    $("#StoreCost").html(DisplayLarge(Math.pow(7.53e9,CurrentStoresAvailable+1)))
                    $("#NextStoreMod").html("another")
                    if(CurrentStoresAvailable>1){
                        $("#StoreText").html("Buy "+CurrentStoresAvailable+" Toy Stores")
                    }else{
                        $("#StoreText").html("Buy Toy Store")
                    }
                }else if(CurrentStoresAvailable<=0){
                    $("#StoreCost").html(DisplayLarge(7.53e9))
                    $("#NextStoreMod").html("a")
                    $("#StoreText").html("Buy Toy Store")
                }
                if(CurrentStoresAvailable>=5){
                    $("#NextStore").hide()
                }else{
                    $("#NextStore").show()
                }
            }else{
                $("#NextStore").show()
                $("#StoreCost").html(DisplayLarge(7.53e9))
                $("#NextStoreMod").html("a")
                $("#StoreText").html("Buy Toy Store")
            }
            if(hUpgrades.AutoStores == "yes"&&hUpgrades.AutoStoreOn=="yes"){
                var CurrentStoresAvailable = Math.max(0,Math.floor(Math.log(Believers)/Math.log(7.53e9)))
                if(CurrentStoresAvailable>=hUpgrades.AutoStoreAMT){
                    BuyStore(true)
                    //console.log("AutoBuying "+CurrentStoresAvailable+" Stores")
                }
            }
            /*if(hUpgrades["TwoStores"]=="yes"){
                if(Loyalty>=1e300){
                    $("#StoreText").html("Buy 2 Toy Stores")
                    if(hUpgrades["AutoStores"]=="yes"){
                        BuyStore(true)
                    }
                }else{
                    $("#StoreText").html("Buy Toy Store")
                }
            }*/
            var StoreUpgradesAvailable = false
            $(".StoreHolder").each(function(){
                if($(this).hasClass("Money")){
                    var mCost = ReadLarge($(this).find(".Cost").html())
                    //console.log("Money: "+$(this).attr("id")+": "+mCost)
                    if(Money>=mCost){
                        $(this).find(".Upgrade").prop("disabled",false)
                        StoreUpgradesAvailable = true
                    }else{
                        $(this).find(".Upgrade").prop("disabled",true)
                    }
                    if($(this).attr("id")=="MoneyIcons" && sIcons>=5){
                        $(this).find(".Upgrade").html("Max Icons")
                        $(this).find(".Upgrade").prop("disabled",true)
                        $(this).find(".Cost").hide()
                    }else if($(this).attr("id")=="MoneyIcons"){
                        $(this).find(".Upgrade").html("Add More<br>Icon Slots")
                        $(this).find(".Cost").show()
                    }
                }else if($(this).hasClass("Automator")){
                    var HireFire = $(this).find(".HireFire")
                    var sCost = Number($(this).find(".Salary").html())
                    //console.log("Automator: "+$(this).attr("id")+": "+sCost)
                    if(Income>=sCost){
                        $(this).find(".Upgrade").prop("disabled",false)
                        if(HireFire.html()=="Hire"){
                            $(this).find(".Upgrade").css("background-color","#4CAF50")
                            //StoreUpgradesAvailable = true
                        }else{
                            $(this).find(".Upgrade").css("background-color","rgb(175, 76, 76)")
                        }
                    }else if(HireFire.html()=="Hire"){
                        $(this).find(".Upgrade").prop("disabled",true)
                        $(this).find(".Upgrade").css("background-color","grey")
                    }else if(HireFire.html()=="Fire"){
                        $(this).find(".Upgrade").css("background-color","rgb(175, 76, 76)")
                        $(this).find(".Upgrade").prop("disabled",false)
                    }
                    //console.log($(this).attr("id").substr(1),hUpgrades.PermaBuyers[$(this).attr("id").substr(1)])
                    if(hUpgrades.PermaBuyers[$(this).attr("id").substr(1)]=="yes"){
                        if(HireFire.html()=="Fire"){
                            $(this).find(".Upgrade").prop("disabled",true)
                            $(this).find(".Upgrade").css("background-color","rgb(53, 79, 58)")
                            $(this).find(".HireFire").hide()
                            $(this).find(".HFBR").hide()
                        }else{
                            HireFire.html("Fire")
                            $(this).find(".Upgrade").prop("disabled",true)
                            $(this).find(".Upgrade").css("background-color","rgb(53, 79, 58)")
                            $(this).find(".HireFire").hide()
                            $(this).find(".HFBR").hide()
                        }
                    }else{
                        $(this).find(".HireFire").show()
                        $(this).find(".HFBR").show()
                    }
                }
            })
            if(StoreAvailable||StoreUpgradesAvailable){
                $("#ToyStoreMenu").css("filter","grayscale(0)")
            }else{
                $("#ToyStoreMenu").css("filter","grayscale(1)")
            }
            ShowBenefits()
        }
        function BuyStore(AutoStore){
            StoreAvailable = (Believers>=7.53e9)
            var StoresEarned = 1
            if(StoreAvailable){
                if(hUpgrades.MultiStores=="no"){
                    Stores += (1+(ExtraIncome*5)) * NYUpgrades.EmpireIncomeMulti
                    Income += (0.2+ExtraIncome) * NYUpgrades.EmpireIncomeMulti
                }else if(hUpgrades.MultiStores=="yes"){
                    var CurrentStoresAvailable = Math.max(0,Math.floor(Math.log(Believers)/Math.log(7.53e9)))
                    //console.log("Got "+CurrentStoresAvailable+" Stores")
                    Stores += (CurrentStoresAvailable+(ExtraIncome*5*CurrentStoresAvailable)) * NYUpgrades.EmpireIncomeMulti
                    Income += ((CurrentStoresAvailable/5)+(ExtraIncome*CurrentStoresAvailable)) * NYUpgrades.EmpireIncomeMulti
                    StoresEarned = CurrentStoresAvailable
                }
            }
            Income = Number(Income.toFixed(2))
            $("#MoneyMin").html(Income.toFixed(2))
            $(".NetMoney").each(function(){
                $(this).html((Stores*.2).toFixed(2))
            })
            StoreReset()
            StoreCheck()
            IncomeCheck()
            if(hUpgrades.FirstSpin == "yes"){
                var Score = 25*TotalMulti()
                ProcessScore(Score)
            }
            //AchievementCheck()
            if(!AutoStore){
                Analytics('event', 'Buy Store', {'event_category':"Prestige", "Stores": Stores })
            }else{
                //console.log("Autoed")
            }
            /*--Log Prestige--*/
            if(kongregate){kongregate.stats.submit('Toy Stores', StoresEarned)}
        }
        function StoreReset(){
            /*--Reset Automation Variables--*/
                if(NYUpgrades.RetainAutomation=="no"){
                    AutoSpinUnlocked = "no"
                    AutoStopUnlocked = "no"
                    AutoStopSpeed = 1000
                    /*--Stop Reels--*/
                        for(var ReelStop = 1;ReelStop<=5;ReelStop++){
                            Machines[ReelStop].stop()
                        }
                        $("#SpinReels").prop("disabled",false)
                }
            /*--Reset Basic Variables--*/
                TotalScore = 0
                LifetimeScore = 0
                BasicMultiplier = 1
                StopAllUnlocked = "no"
            /*--Reset Loyalty Variables--*/
                Believers = 0
                VisibleLines = 3
                BelieverMulti = 1
                FlakeIsWild = "no"
            /*--Reset Costs--*/
                for(var RegUp in BaseCosts){
                    $(".UpgradeHolder#"+RegUp).find(".Cost").html(DisplayLarge(BaseCosts[RegUp]))
                }
                for(var lUp in BaseLCosts){
                    $(".BelUpgradeHolder#"+lUp).find(".Cost").html(DisplayLarge(BaseLCosts[lUp]))
                }
            /*--Display Variables--*/
                $("#AvailBelievers").html(0)
                $(".Believers").each(function(){
                    $(this).html(DisplayLarge(Believers))
                })
                $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
            /*--Save Variables--*/
                SaveData()
            /*--Check Updates--*/
                AllChecks()
        }
        function IncomeCheck(){
            $("#MoneyMin").html(Income.toFixed(2))
            $(".NetMoney").each(function(){
                $(this).html((Stores*.2).toFixed(2))
            })
            $("#WarpEarnings").html(DisplayLarge(Income*120))
            if(Income<.6&&Income>0){
                IncomeInterval = 1/(Income*100)*60000
            }else{
                IncomeInterval = 1000
            }
            clearInterval(Earning)
            Earning = setInterval(function(){
                var PerGo = Income*(IncomeInterval/60000)
                Money += Number(PerGo.toFixed(2))
                Money = Number(Money.toFixed(2))
                //console.log(PerGo+" "+IncomeInterval)
                $("#Money").html(Money.toFixed(2))
                StoreCheck()
                AutoBuy("autoMoneyPoints","Store")
                /*if(EmpireComps > 0){
                    AutoBuy("autoMoneyIcons","Store")
                    AutoBuy("autoMoneyPoints","Store")
                }*/
            },IncomeInterval)
        }
        function StorePurchase(pID){
            var StoreCost = ReadLarge($(".StoreHolder#"+pID).find(".CostLabel").find("span").html())
            var CostText = $(".StoreHolder#"+pID).find(".CostLabel").find("span")
            if(pID=="MoneyPoints"){
                if(Money>=StoreCost){
                    Money -= StoreCost
                    $("#Money").html(Money.toFixed(2))
                    sMultiplier *= NYUpgrades.StoreMulti
                    if(StoreCost==.1){StoreCost=.2}
                    StoreCost *= 2
                    if(StoreCost<1000){
                        CostText.html(StoreCost.toFixed(2))
                    }else{
                        CostText.html(DisplayLarge(StoreCost))
                    }
                    Analytics('event', 'Upgrade', {'event_category':"Store", 'event_label':"3x Multi", "Cost": StoreCost/2})
                }
            }/*else if(pID=="MoneyIcons"){
                StoreCost = ReadLarge($(".StoreHolder#"+pID).find(".CostLabel").find("span").html())
                if(Money>=StoreCost){
                    Money -= StoreCost
                    $("#Money").html(Money.toFixed(2))
                    sIcons += 1
                    StoreCost *= 10
                    CostText.html(DisplayLarge(StoreCost))
                    ResetScratch("#FirstScratch")
                    Analytics('event', 'Upgrade', {'event_category':"Store", 'event_label':"Icons", "Cost": StoreCost/2})
                }
            }*/else{
                var HireFire = $(".StoreHolder#"+pID).find(".HireFire")
                if(Income>=StoreCost && HireFire.html() =="Hire"){
                    Income -= StoreCost
                    Income = Number(Income.toFixed(2))
                    $(".StoreHolder#"+pID).find(".Upgrade").css("background-color","rgb(175, 76, 76)")
                    HireFire.html("Fire")
                    Automators["auto"+pID.substr(1)] = "yes"
                    Analytics('event', 'Hire Auto', {'event_category':"Store", 'event_label': pID.substr(1)})
                }else if(HireFire.html() == "Fire"){
                    Income += StoreCost
                    Income = Number(Income.toFixed(2))
                    HireFire.html("Hire")
                    $(".StoreHolder#"+pID).find(".Upgrade").css("background-color","#4CAF50")
                    Automators["auto"+pID.substr(1)] = "no"
                    Analytics('event', 'Fire Auto', {'event_category':"Store", 'event_label': pID.substr(1)})
                }
            }
            IncomeCheck()
            AllChecks()
        }
    
    /*------Store/Button Automation-------*/
        var Automators = {
            autoDoubler: "no",
            autoStoppingSpeed: "no",
            autoGetStopAll: "no",
            autoAutoSpin: "no",
            autoAutoStop: "no",
            autoTripler: "no",
            autoMoreLines: "no",
            autoChangeFlake: "no",
            autoMoneyPoints: "no",
            autoCompanyPoints: "no",
        }
        function ButtonAutomation(){
            //Order
                AutoBuy("autoGetStopAll")
                AutoBuy("autoAutoSpin")
                AutoBuy("autoAutoStop")
                AutoBuy("autoMoreLines","BelUpgrade")
                AutoBuy("autoChangeFlake","BelUpgrade")
                AutoBuy("autoDoubler")
                AutoBuy("autoTripler","BelUpgrade")
                AutoBuy("autoStoppingSpeed")
                AutoBuy("autoMoneyPoints","Store")
                AutoBuy("autoCompanyPoints","Company")
            /*for(Automator in Automators){
                AutoBuy(Automator)
            }*/
        }
        function AutoBuy(Automator,NonNormal){
            var aUpgrade = Automator.replace("auto","")
            var Activated = Automators[Automator]=="yes"
            if(!NonNormal){
                var UpgradeCost = ReadLarge($(".UpgradeHolder#"+aUpgrade+" .Cost").html())
                if(Activated&&aUpgrade!="Doubler"){
                    while(UpgradeCost<=TotalScore && UpgradeCost < Infinity && !$(".UpgradeHolder#"+aUpgrade+" .Upgrade").prop("disabled")){
                        Upgrade(aUpgrade,true)
                        UpgradeCost = ReadLarge($(".UpgradeHolder#"+aUpgrade+" .Cost").html())
                    }
                }else if(Activated&&aUpgrade=="Doubler"){
                    while(UpgradeCost<=TotalScore && UpgradeCost < Infinity && !$(".UpgradeHolder#"+aUpgrade+" .Upgrade").prop("disabled")){
                        //console.log(TotalScore,UpgradeCost,aUpgrade)
                        TotalScore -= UpgradeCost
                        BasicMultiplier *= 2
                        if(UpgradeCost==1){
                            UpgradeCost = 3
                        }else if(UpgradeCost==3){
                            UpgradeCost = 10
                        }else{
                            UpgradeCost *= 3
                        }
                    }
                    $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                    $(".UpgradeHolder#"+aUpgrade+" .Cost").html(DisplayLarge(UpgradeCost))
                    UpgradeCheck()
                }
            }else if(Activated){
                if(NonNormal=="BelUpgrade"){
                    var AtLimit = Believers==BelieverLimit
                    var UpgradeCost = ReadLarge($("."+NonNormal+"Holder#"+aUpgrade+" .Cost").html())
                    while(UpgradeCost<=Believers && UpgradeCost < Infinity && !$("."+NonNormal+"Holder#"+aUpgrade+" .Upgrade").prop("disabled")){
                        BelieverUpgrade(aUpgrade,true)
                        UpgradeCost = ReadLarge($("."+NonNormal+"Holder#"+aUpgrade+" .Cost").html())
                    }
                    if(AtLimit){
                        Believers=BelieverLimit
                        ShowBenefits()
                    }
                }
                if(NonNormal=="Store"){
                    var UpgradeCost = ReadLarge($("."+NonNormal+"Holder#"+aUpgrade+" .Cost").html())
                    while(UpgradeCost<=Money && UpgradeCost < Infinity && !$("."+NonNormal+"Holder#"+aUpgrade+" .Upgrade").prop("disabled")){
                        StorePurchase(aUpgrade)
                        UpgradeCost = ReadLarge($("."+NonNormal+"Holder#"+aUpgrade+" .Cost").html())
                    }
                }
                if(NonNormal=="Company"){
                    var UpgradeCost = ReadLarge($("."+NonNormal+"Holder#"+aUpgrade+" .Cost").html())
                    var CompanyUComplete = true
                    for(var cu in hUpgrades){
                        if(cu!="PermaBuyers"&&cu!="CardTrans"&&hUpgrades[cu]=="no"){
                            CompanyUComplete = false
                        }else if(cu=="PermaBuyers"){
                            for(var PB in hUpgrades[cu]){
                                if(hUpgrades[cu][PB]=="no"){
                                    CompanyUComplete = false
                                }
                            }
                        }
                    }
                    while(CompanyUComplete&&UpgradeCost<=HPoints && UpgradeCost < Infinity && !$("."+NonNormal+"Holder#"+aUpgrade+" .Upgrade").prop("disabled")){
                        CompanyUpgrade(aUpgrade)
                        UpgradeCost = ReadLarge($("."+NonNormal+"Holder#"+aUpgrade+" .Cost").html())
                    }
                }
            }
        }
        function LoadStore(){
            
            LoadAutomators()
        }
        function LoadAutomators(){
            for(var Automator in Automators){
                var aUpgrade = Automator.replace("auto","a")
                var Activated = Automators[Automator]=="yes"
                //console.log(aUpgrade)
                if(Activated){
                    $(".Upgrade#"+aUpgrade).prop("disabled",false)
                    $(".Upgrade#"+aUpgrade).css("background-color","rgb(175, 76, 76)")
                    $(".Upgrade#"+aUpgrade).find(".HireFire").html("Fire")
                }
                
            }
        }
    /*------Company-------*/
        /*--Company Variables--*/
            var Companies = 0
            var LifetimeCompanies = 0
            var HPoints = 0
            var StoreThresh = 20
            var cMultiplier = 1
            var hUpgrades ={
                AutoDelivery: "no",
                FirstSpin: "no",
                MultiStores: "no",
                AutoStores: "no",
                AutoStoreAMT: 2,
                AutoStoreOn: "no",
                PermaBelUpgrades: "no",
                PermaAutoUpgrades: "no",
                PermaBuyers: {
                    "Doubler": "no",
                    "StoppingSpeed": "no",
                    "GetStopAll": "no",
                    "AutoSpin": "no",
                    "AutoStop": "no",
                    "Tripler": "no",
                    "MoreLines": "no",
                    "ChangeFlake": "no",
                }
            }
            var BaseCCosts = {
                CompanyPoints: 1
            }

        /*--Company Check--*/
            function CompanyCheck(){
                $("#HPoints").html(HPoints)
                $("#Companies").html(Companies)
                //Set Threshold
                    StoreThresh = 20 + (Companies*5)
                    var YearlyThresh = (StoreThresh * .1)
                    var IncomeThresh = (StoreThresh *.2).toFixed(0)
                    if(YearlyThresh%1!=0){
                        YearlyThresh = YearlyThresh.toFixed(1)
                    }else{
                        YearlyThresh = YearlyThresh.toFixed(0)
                    }
                    $("#YearlyThresh").html(YearlyThresh)
                    $("#IncomeThresh").html(IncomeThresh)
                //Check Threshold
                    var CompanyAvailable = (Stores>=StoreThresh)
                if(CompanyAvailable || Companies>= 1){
                    //$("#MenorahMenu").css("filter","grayscale(0)")
                    if(CompanyAvailable){
                        $("#CompanyIcon").css("filter","grayscale(0)")
                        $(".BuyCompanyButton").prop("disabled",false)
                    }else{
                        $("#CompanyIcon").css("filter","grayscale(1)")
                        $(".BuyCompanyButton").prop("disabled",true)
                    }
                }else{
                    //$("#MenorahMenu").css("filter","grayscale(1)")
                    $("#CompanyIcon").css("filter","grayscale(1)")
                    $(".BuyCompanyButton").prop("disabled",true)
                }
                var CompanyUpgradesAvailable = false
                $(".CompanyHolder").each(function(){
                    if($(this).hasClass("Multi")){
                        if(hUpgrades["CardTrans"]=="no"){
                            $(this).find(".CompanyUpgrade").prop("disabled",true)
                        }else{
                            var CorpCost = Number($(this).find(".Cost").html())
                            var UpgradeAvailable = (HPoints>=CorpCost)
                            if(UpgradeAvailable){
                                $(this).find(".CompanyUpgrade").prop("disabled",false)
                                CompanyUpgradesAvailable = true
                            }else{
                                $(this).find(".CompanyUpgrade").prop("disabled",true)
                            }
                        }
                    }else{
                        var CorpCost = Number($(this).find(".Cost").html())
                        var UpgradePurchased = hUpgrades[$(this).attr("id")]=="yes"
                        if($(this).hasClass("Perma")){
                            UpgradePurchased = hUpgrades.PermaBuyers[$(this).attr("id").replace("Perma","")]=="yes"
                            }
                        var UpgradeAvailable = (HPoints>=CorpCost && !UpgradePurchased)
                        if(UpgradeAvailable){
                            $(this).find(".CompanyUpgrade").css({
                                "background-image": "none",
                                "text-shadow": "none",
                                "padding-top": "0px"
                            })
                            $(this).find(".CompanyUpgrade").prop("disabled",false)
                            CompanyUpgradesAvailable = true
                        }else{
                            $(this).find(".CompanyUpgrade").prop("disabled",true)
                            if(UpgradePurchased){
                                $(this).find(".CompanyUpgrade").css({
                                    "background-color": "rgb(53, 79, 58)",
                                    "background-image": "url('Images/Support/HanBack.png')",
                                    "background-size": "cover",
                                    "text-shadow": "0 0 10px #000",
                                    "padding-top": "10px"
                                })
                                var AutoSet
                                //Changes if Purchased
                                    switch($(this).attr("id")){
                                        case "MultiStores":
                                            BelieverLimit = 1e50
                                            break;
                                        case "AutoStores":
                                            $(".CompanyHolder#AutoStores .SubLabel").hide()
                                            $("#AutoStoreCustom").show()
                                            $("#AutoStoreAMT").val(Number(hUpgrades.AutoStoreAMT))
                                            $("#AutoStoreCheck").prop("checked",hUpgrades.AutoStoreOn=="yes")
                                            if(hUpgrades.AutoStoreOn=="yes"){
                                                $("#AutoStoreCheck").prop("checked",true)
                                            }else{
                                                $("#AutoStoreCheck").prop("checked",false)
                                            }
                                            break;
                                        case "AutoDelivery":
                                            $(".BelieverPrestige").hide()
                                            break;
                                        case "PermaBelUpgrades":
                                            AutoSet = ['aMoreLines','aChangeFlake']
                                            for(var aNum in AutoSet){
                                                if(hUpgrades.PermaBuyers[AutoSet[aNum].replace("a","")]=="no"){
                                                    var pID = AutoSet[aNum]
                                                    hUpgrades.PermaBuyers[pID.replace("a","")]="yes"
                                                    $(".StoreHolder#"+pID).find(".Upgrade").prop("disabled",true)
                                                    $(".StoreHolder#"+pID).find(".Upgrade").css("background-color","rgb(53, 79, 58)")
                                                    $(".StoreHolder#"+pID).find(".HireFire").html("Fire")
                                                    Automators["auto"+pID.substr(1)] = "yes"
                                                }
                                            }
                                            break;
                                        case "PermaAutoUpgrades":
                                            AutoSet = ['aGetStopAll','aAutoSpin','aAutoStop','aStoppingSpeed']
                                            for(var aNum in AutoSet){
                                                if(hUpgrades.PermaBuyers[AutoSet[aNum].replace("a","")]=="no"){
                                                    var pID = AutoSet[aNum]
                                                    hUpgrades.PermaBuyers[pID.replace("a","")]="yes"
                                                    $(".StoreHolder#"+pID).find(".Upgrade").prop("disabled",true)
                                                    $(".StoreHolder#"+pID).find(".Upgrade").css("background-color","rgb(53, 79, 58)")
                                                    $(".StoreHolder#"+pID).find(".HireFire").html("Fire")
                                                    Automators["auto"+pID.substr(1)] = "yes"
                                                }
                                            }
                                            break;
                                    }
                            }else{
                                $(this).find(".CompanyUpgrade").css({
                                    "background-image": "none",
                                    "text-shadow": "none",
                                    "padding-top": "0px"
                                })
                                //Changes if Unpurchased
                                    switch($(this).attr("id")){
                                        case "MultiStores":
                                            BelieverLimit = 7.53e9
                                            break;
                                        case "AutoStores":
                                            $("#AutoStoreCustom").hide()
                                            $(".CompanyHolder#AutoStores .SubLabel").show()
                                            break;
                                        case "AutoDelivery":
                                            $(".BelieverPrestige").show()
                                            break;
                                    }
                            }
                        }
                    }
                })
                if(hUpgrades.MultiStores=="no"){
                    $(".CompanyHolder#AutoStores .CompanyUpgrade").prop("disabled",true)
                }
                if(CompanyAvailable||CompanyUpgradesAvailable){
                    $("#MenorahMenu").css("filter","grayscale(0)")
                }else{
                    $("#MenorahMenu").css("filter","grayscale(1)")
                }
                if(NYUpgrades.MultiComp == "yes"&&CompanyAvailable){
                    var HPointsAvailable = CompaniesAvail()[0]
                    $("#HPointsAvailable").html(" For "+HPointsAvailable+" HPoints")
                    $(".BuyCompanyButton").width(155)
                    if(HPointsAvailable<3){
                        $("#AnotherHPoint").show()
                        $("#MenorahPopup .ScrollBody").height(215)
                        var IncomeNeed = CompaniesAvail()[2].toFixed(2)
                        $("#StoresNeeded").html(IncomeNeed)
                    }else{
                        $("#AnotherHPoint").hide()
                        $("#MenorahPopup .ScrollBody").height(230)
                    }
                }else{
                    $("#HPointsAvailable").html("")
                    $(".BuyCompanyButton").width(110)
                    $("#AnotherHPoint").hide()
                    $("#MenorahPopup .ScrollBody").height(230)
                }
                if(CompanyAvailable&&NYUpgrades.AutoCompanies=="yes"&&NYUpgrades.AutoCompanyOn=="yes"){
                    if(NYUpgrades.MultiComp == "yes"){
                        if(HPointsAvailable>=NYUpgrades.AutoCompanyAMT){
                            MakeCompany()
                        }
                    }else{
                        MakeCompany()
                    }
                }
                ShowBenefits()
            }
            /*function CompaniesAvailable(){
                var CompsAvail = Math.floor(Math.sqrt(8*Stores + 5*Math.pow(2*Companies + 7,2))/(2*Math.sqrt(5)) - Companies - 7/2)
                //
                //Math.floor(0.5*(Math.sqrt((2*Stores)+Math.pow(2*Companies+9,2))-(2*Companies)-9))
                if(CompsAvail>3){
                    CompsAvail = 3
                }
                return CompsAvail
            }
            function StoresNeeded(){
                var NextComp = CompaniesAvailable()+1
                var NeededForNext = 5/2*(Math.pow(NextComp,2)+((7+((Companies)*2))*NextComp))
                //Math.floor(2*(Math.pow(NextComp,2)+(9+(Companies*2))*NextComp))
                return NeededForNext-Stores
            }*/
            function CompaniesAvail(){
                var TempThresh = StoreThresh
                var ThreshTotal = StoreThresh
                var EarnedCount = 0
                var StoresRemaining = 0
                    while(Stores>=ThreshTotal&&EarnedCount<3){
                        if(TempThresh<50){
                            TempThresh += 5
                        }else{
                            TempThresh += 5
                        }
                        ThreshTotal += TempThresh
                        EarnedCount += 1
                    }
                    var StoresRemaining = (ThreshTotal - Stores)
                    if(EarnedCount>=3){StoresRemaining=0}
                    var IncomeRemaining = StoresRemaining/5
                return [EarnedCount,StoresRemaining,IncomeRemaining]
            }
        /*--Get Company--*/
            function MakeCompany(){
                var CompanyAvailable = (Stores>=StoreThresh)
                var CompaniesEarned = 1
                if(CompanyAvailable){
                    if(NYUpgrades.MultiComp == "yes"){
                        var HPointsAvailable = CompaniesAvail()[0]//CompaniesAvailable()
                        Companies += HPointsAvailable
                        LifetimeCompanies += HPointsAvailable
                        HPoints += HPointsAvailable
                        CompaniesEarned = HPointsAvailable
                    }else{
                        Companies += 1
                        LifetimeCompanies +=1
                        HPoints += 1
                    }
                    $("#HPoints").html(HPoints)
                    $("#Companies").html(Companies)
                    CompanyReset()
                    CompanyCheck()
                    AutoBuy("autoCompanyPoints","Company")
                    EmpireCheck()
                    AchievementCheck()
                    Analytics('event', 'Hanukkah', {'event_category':"Prestige", "Companies": Companies })
                    if(NYUpgrades.AutoCompanySpin == "yes"){
                        var Score = 25*TotalMulti()
                        ProcessScore(Score)
                    }
                    /*--Log Prestige--*/
                        if(kongregate){kongregate.stats.submit('HPoints', CompaniesEarned)}
                }
            }
            function CompanyReset(){
                /*--Reset Automation Variables--*/
                    if(NYUpgrades.RetainAutomation=="no"){
                        AutoSpinUnlocked = "no"
                        AutoStopUnlocked = "no"
                        AutoStopSpeed = 1000
                        /*--Stop Reels--*/
                            for(var ReelStop = 1;ReelStop<=5;ReelStop++){
                                Machines[ReelStop].stop()
                            }
                            $("#SpinReels").prop("disabled",false)
                    }
                /*--Reset Basic Variables--*/
                    TotalScore = 0
                    LifetimeScore = 0
                    BasicMultiplier = 1
                    StopAllUnlocked = "no"
                /*--Reset Loyalty Variables--*/
                    Believers = 0
                    VisibleLines = 3
                    BelieverMulti = 1
                    FlakeIsWild = "no"
                /*--Reset Automators--*/
                    //if(hUpgrades["PermaBuyers"]=="no"){
                        for(var Automator in Automators){
                            permaed = hUpgrades.PermaBuyers[Automator.replace("auto","")]=="yes"||Automator=="autoMoneyPoints"||Automator=="autoMoneyIcons"||Automator=="autoCompanyPoints"
                            if(!permaed){
                                var aUpgrade = Automator.replace("auto","a")
                                var HireFire = $(".StoreHolder#"+aUpgrade).find(".HireFire")
                                HireFire.html("Hire")
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).find(".Upgrade").css("background-color","grey")
                                Automators[Automator] = "no"
                            }
                        }
                    //}
                /*--Reset Store--*/
                    Stores = 0
                    Income = 0
                    sMultiplier = 1
                    IncomeInterval = 1000

                    IncomeCheck()
                    Money = 0
                /*--Reset Costs--*/
                    for(var RegUp in BaseCosts){
                        $(".UpgradeHolder#"+RegUp).find(".Cost").html(DisplayLarge(BaseCosts[RegUp]))
                    }
                    for(var lUp in BaseLCosts){
                        $(".BelUpgradeHolder#"+lUp).find(".Cost").html(DisplayLarge(BaseLCosts[lUp]))
                    }
                    for(var sUp in BaseSCosts){
                        $(".StoreHolder#"+sUp).find(".Cost").html(DisplayLarge(BaseSCosts[sUp]))
                    }
                /*--Display Variables--*/
                    $("#AvailBelievers").html(0)
                    $(".Believers").each(function(){
                        $(this).html(DisplayLarge(Believers))
                    })
                    $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                /*--Save Variables--*/
                    SaveData()
                /*--Check Updates--*/
                    AllChecks()
                
            }
        /*--Company Upgrades--*/
            function CompanyUpgrade(cID){
                var CorpCost = Number($(".CompanyHolder#"+cID).find(".Cost").html())
                if($(".CompanyHolder#"+cID).hasClass("Multi")){
                    if(HPoints>=CorpCost){
                        HPoints -= CorpCost
                        cMultiplier *= NYUpgrades.CompMulti
                        CorpCost += 1
                        $(".CompanyHolder#"+cID).find(".Cost").html(CorpCost)
                        Analytics('event', 'Upgrade', {'event_category':"Hanukkah", 'event_label':cID, "Cost": CorpCost-1})
                    }
                }else if($(".CompanyHolder#"+cID).hasClass("Perma")){
                    var UpgradePurchased = hUpgrades.PermaBuyers[cID.replace("Perma","")]=="yes"
                    if(HPoints>=CorpCost && !UpgradePurchased){
                        HPoints -= CorpCost
                        hUpgrades.PermaBuyers[cID.replace("Perma","")]="yes"
                        pID = cID.replace("Perma","a")
                        $(".StoreHolder#"+pID).find(".Upgrade").prop("disabled",true)
                        $(".StoreHolder#"+pID).find(".Upgrade").css("background-color","rgb(53, 79, 58)")
                        $(".StoreHolder#"+pID).find(".HireFire").html("Fire")
                        Automators["auto"+pID.substr(1)] = "yes"
                        Analytics('event', 'Upgrade', {'event_category':"Hanukkah", 'event_label':cID})
                    }
                }else if($(".CompanyHolder#"+cID).hasClass("PermaMult")){
                    var UpgradePurchased = hUpgrades[cID]=="yes"
                    if(HPoints>=CorpCost && !UpgradePurchased){
                        HPoints -= CorpCost
                        hUpgrades[cID]= "yes"
                        var AutoSet = []
                        switch(cID){
                            case "PermaBelUpgrades":
                                AutoSet = ['aMoreLines','aChangeFlake']
                                break;
                            case "PermaAutoUpgrades":
                                AutoSet = ['aGetStopAll','aAutoSpin','aAutoStop','aStoppingSpeed']
                                break;
                        }
                        for(var aNum in AutoSet){
                            pID = AutoSet[aNum]
                            hUpgrades.PermaBuyers[pID.replace("a","")]="yes"
                            $(".StoreHolder#"+pID).find(".Upgrade").prop("disabled",true)
                            $(".StoreHolder#"+pID).find(".Upgrade").css("background-color","rgb(53, 79, 58)")
                            $(".StoreHolder#"+pID).find(".HireFire").html("Fire")
                            Automators["auto"+pID.substr(1)] = "yes"
                        }
                        
                        Analytics('event', 'Upgrade', {'event_category':"Hanukkah", 'event_label':cID})
                    }
                }else{
                    var UpgradePurchased = hUpgrades[cID]=="yes"
                    if(HPoints>=CorpCost && !UpgradePurchased){
                        HPoints -= CorpCost

                        hUpgrades[cID]= "yes"
                        switch(cID){
                            case "AutoStores":
                                $("#AutoStoreCheck").prop("checked",true)
                                hUpgrades.AutoStoreOn = "yes"
                                break;
                        }
                        Analytics('event', 'Upgrade', {'event_category':"Hanukkah", 'event_label':cID})
                    }
                }
                AllChecks()
            }
    /*------New Year-------*/
        /*--Empire Variables--*/
            var EmpireComps = 0
            var LifetimeMonths = 0
            var Months = 0
            var TotalMonths = 0
            var NYPrestiges = 0

            var NYUpgrades ={
                EmpireIncomeMulti: 1,
                EmpireMulti: 1,
                AutoCompanies: "no",
                MultiComp: "no",
                AutoCompanyAMT: 1,
                AutoCompanyOn: "no",
                RetainAutomation: "no",
                RetainPermas: "no",
                AutoCompanySpin: "no",
                StoreMulti: 3,
                CompMulti: 5,
                PermaBuyers: {
                    AutoDelivery: "no",
                    FirstSpin: "no",
                    MultiStores: "no",
                    AutoStores: "no"
                }
            }
            var empBaseline ={
                EmpireIncomeMulti: 1,
                EmpireMulti: 1,
                AutoCompanies: "no",
                MultiComp: "no",
                AutoCompanyAMT: 1,
                AutoCompanyOn: "no",
                RetainAutomation: "no",
                RetainPermas: "no",
                AutoCompanySpin: "no",
                StoreMulti: 3,
                CompMulti: 5,
                PermaBuyers: {
                    AutoDelivery: "no",
                    FirstSpin: "no",
                    MultiStores: "no",
                    AutoStores: "no"
                }
            }

            var BaseECosts = {
                EmpireIncomeMulti: 1,
                EmpireMulti: 2
            }

        /*--Empire Hooks--*/
            function EmpireHooks(){
                $(".EmpireUpgrade").on('click', function() {
                    EmpireUpgrade($(this).attr("id"))
                })
                $(".MergeEmpire").on('click', function() {
                    var AvailableCreds = CreditChecker(Companies)[0]
                    BasicConfirm("Yearly Retirement",'Are you sure you would like to retire for '+AvailableCreds+' Productive Months and reset company, store, loyalty, and basic upgrades?',"GetEmpire()")
                })
            }
        /*--Empire Check--*/
            function CreditChecker(yourpoints){
                var thesum = 0
                var currentnum = 0
                var currentpoints = 0
                var nextsum = 0
                while(nextsum<=yourpoints){
                    currentnum += 10
                    currentpoints += 1
                    thesum += currentnum
                    nextsum += 10
                }
                var theremainder = nextsum-yourpoints
                return [currentpoints,thesum,theremainder]
            }
            function EmpireCheck(){
                $("#Months").html(Months)
                $("#TotalMonths").html(TotalMonths)
                var CreditCheck = CreditChecker(Companies)
                var AvailableCreds = CreditCheck[0]
                if(AvailableCreds<3){
                    $("#AvailableCredits").html(0)
                    $("#CredRemainder").html(CreditCheck[2])
                    $(".CR").hide()
                }/*else if(AvailableCreds<=3&&LifetimeMonths<1){
                    $("#AvailableCredits").html(AvailableCreds)
                    $("#CredRemainder").html(CreditCheck[2])
                    $(".CR").hide()
                }*/else{
                    $("#AvailableCredits").html(AvailableCreds)
                    $("#CredRemainder").html(CreditCheck[2])
                    $(".CR").show()
                }
                /*--Check Company Upgrades--*/
                    var CompanyUComplete = true
                    for(var cu in hUpgrades){
                        if(cu!="PermaBuyers"&&cu!="AutoStoreOn"&&hUpgrades[cu]=="no"){
                            CompanyUComplete = false
                        }else if(cu=="PermaBuyers"){
                            for(var PB in hUpgrades[cu]){
                                if(hUpgrades[cu][PB]=="no"){
                                    CompanyUComplete = false
                                }
                            }
                        }
                    }
                    //console.log(CompanyUComplete)
                /*--Check Empire Availability--*/
                    var EmpireAvailable = CompanyUComplete && AvailableCreds>2
                    if(EmpireAvailable){
                        $(".MergeEmpire").prop("disabled",false)
                        $("#EmpireIcon").css("filter","grayscale(0)")
                    }else{
                        $(".MergeEmpire").prop("disabled",true)
                        $("#EmpireIcon").css("filter","grayscale(1)")
                    }
                /*--Check Upgrades--*/
                    var EmpireUpgradesAvailable = EmpireUpgradeCheck()
                /*--Color Icon--*/
                    if(EmpireUpgradesAvailable||EmpireAvailable){
                        $("#NewYearMenu").css("filter","grayscale(0)")
                    }else{
                        $("#NewYearMenu").css("filter","grayscale(1)")
                    }
                    
            }
            function EmpireUpgradeCheck(){
                var eUpgradesAvailable = false
                $(".EmpireHolder").each(function(){
                    var ECCost = Number($(this).find(".Cost").html())
                    if($(this).hasClass("Multi")){
                        var UpgradeAvailable = (Months>=ECCost)
                        if(UpgradeAvailable){
                            $(this).find(".EmpireUpgrade").prop("disabled",false)
                            eUpgradesAvailable = true
                        }else{
                            $(this).find(".EmpireUpgrade").prop("disabled",true)
                        }
                        if($(this).attr("id") == "EmpireIncomeMulti"){
                            $("#YearPerStore").html(((100+(ExtraIncome*500)) * NYUpgrades.EmpireIncomeMulti).toFixed(0))
                            $("#MinPerStore").html(((20+(ExtraIncome*100)) * NYUpgrades.EmpireIncomeMulti).toFixed(0))
                            $("#ExtraIncome").html((ExtraIncome* NYUpgrades.EmpireIncomeMulti).toFixed(2))
                            $("#IncomeAdd").html(((10)* NYUpgrades.EmpireIncomeMulti))
                            if(NYUpgrades.EmpireIncomeMulti==2){
                                $(this).find(".Cost").html(15)
                            }
                        }    
                    }else if($(this).hasClass("Auto")){
                        var UpgradePurchased = Automators[$(this).attr("id")] == "yes"
                        var UpgradeAvailable = (Months>=ECCost && !UpgradePurchased)
                        if(UpgradeAvailable){
                            $(this).find(".EmpireUpgrade").prop("disabled",false)
                            eUpgradesAvailable = true
                        }else{
                            $(this).find(".EmpireUpgrade").prop("disabled",true)
                            if(UpgradePurchased){
                                $(this).find(".EmpireUpgrade").css({
                                    "background-image": "url('Images/Support/NewYearBack.jpg')",
                                    "background-size": "cover",
                                    "text-shadow": "0 0 10px #000"
                                })
                            }
                        }
                    }else if($(this).hasClass("Perma")){
                        var PermaGrade = $(this).attr("id").replace("Perma","")
                        var UpgradePurchased = NYUpgrades.PermaBuyers[PermaGrade] == "yes"
                        var UpgradeAvailable = (Months>=ECCost && !UpgradePurchased)
                        if(UpgradeAvailable){
                            $(this).find(".EmpireUpgrade").prop("disabled",false)
                            eUpgradesAvailable = true
                        }else{
                            $(this).find(".EmpireUpgrade").prop("disabled",true)
                            if(UpgradePurchased){
                                $(this).find(".EmpireUpgrade").css({
                                    "background-image": "url('Images/Support/NewYearBack.jpg')",
                                    "background-size": "cover",
                                    "text-shadow": "0 0 10px #000"
                                })
                            }
                        }
                    }else{
                        var UpgradePurchased = NYUpgrades[$(this).attr("id")]!=empBaseline[$(this).attr("id")]
                        var UpgradeAvailable = (Months>=ECCost && !UpgradePurchased)
                        if(UpgradeAvailable){
                            $(this).find(".EmpireUpgrade").prop("disabled",false)
                            eUpgradesAvailable = true
                        }else{
                            $(this).find(".EmpireUpgrade").prop("disabled",true)
                            if(UpgradePurchased){
                                $(this).find(".EmpireUpgrade").css({
                                    "background-image": "url('Images/Support/NewYearBack.jpg')",
                                    "background-size": "cover",
                                    "text-shadow": "0 0 10px #000"
                                })
                            }
                        }
                        switch($(this).attr("id")){
                            case "StoreMulti":
                                if(UpgradePurchased){
                                    $("#ShowStoreMulti").html("Quadruple")
                                }else{
                                    $("#ShowStoreMulti").html("Triple")
                                }
                                break;
                            case "CompMulti":
                                $("#ShowCompMulti").html(NYUpgrades.CompMulti)
                                break;
                            case "AutoCompanies":
                                if(UpgradePurchased){
                                    $("#AutoCompAMT").val(Number(NYUpgrades.AutoCompanyAMT))
                                    $("#AutoCompCheck").prop("checked",NYUpgrades.AutoCompanyOn=="yes")
                                    $("#AutoCompToggle").show()
                                    if(NYUpgrades.MultiComp=="yes"){
                                        $("#AutoCompCustom").show()
                                    }else{
                                        $("#AutoCompCustom").hide()
                                    }
                                }else{
                                    $("#AutoCompCustom").hide()
                                    $("#AutoCompToggle").hide()
                                }
                                break;
                        }
                    }
                    if($(this).hasClass("Req")){
                        switch($(this).attr("id")){
                            case "PermaAutoStores":
                                if(NYUpgrades.PermaBuyers.MultiStores == "no"){
                                    $(this).find(".EmpireUpgrade").prop("disabled",true)
                                }
                                break;
                            case "autoCompanyPoints":
                                var isAvailable = true
                                for(var ePB in NYUpgrades.PermaBuyers){
                                    if(NYUpgrades.PermaBuyers[ePB] == "no"){
                                        isAvailable = false
                                    }
                                }
                                if(!isAvailable){
                                    $(this).find(".EmpireUpgrade").prop("disabled",true)
                                }
                                break;
                            case "NewGame":
                                var isAvailable = true
                                for(var NYup in NYUpgrades){
                                    if(NYup=="PermaBuyers"){
                                        for(var NYPerma in NYUpgrades.PermaBuyers){
                                            if(NYUpgrades.PermaBuyers[NYPerma] == "no"){
                                                isAvailable = false
                                            }
                                        }
                                    }else if(NYup!="AutoCompanyAMT"&&NYup!="AutoCompanyOn"){
                                        if(NYUpgrades[NYup]==empBaseline[NYup]){
                                            isAvailable = false
                                        }
                                    }
                                }
                                if(Automators.autoMoneyPoints=="no"||Automators.autoCompanyPoints=="no"){
                                    isAvailable = false
                                }
                                if(isAvailable){
                                    ACHvars.YouWin = "yes"
                                    $(this).find("#About").show()
                                    $(this).find("#Thanks").show()
                                    $(this).find("#Requirement").hide()
                                    $(this).find(".EmpireUpgrade").css({
                                        "background-image": "url('Images/Support/NGback.png')",
                                        "background-size": "cover",
                                        "text-shadow": "0 0 15px #000"
                                    })
                                    $(this).find(".EmpireUpgrade").prop("disabled",false)
                                }else{
                                    $(this).find("#About").hide()
                                    $(this).find("#Thanks").hide()
                                    $(this).find("#Requirement").show()
                                    $(this).find(".EmpireUpgrade").attr("style","")
                                    $(this).find(".EmpireUpgrade").prop("disabled",true)
                                }
                                break;
                        }
                    }
                })
                ShowBenefits()
                NewGamePlusCheck()
                return eUpgradesAvailable
            }
        /*--Get Empire--*/
            function GetEmpire(){
                var AvailableCreds = CreditChecker(Companies)[0]
                /*--Check Empire Availability--*/
                    var CompanyUComplete = true
                        for(var cu in hUpgrades){ 
                            if(cu!="PermaBuyers"&&hUpgrades[cu]=="no"){
                                CompanyUComplete = false
                            }else if(cu=="PermaBuyers"){
                                for(var PB in hUpgrades[cu]){
                                    if(hUpgrades[cu][PB]=="no"){
                                        CompanyUComplete = false
                                    }
                                }
                            }
                        }
                    var EmpireAvailable = CompanyUComplete && AvailableCreds>2
                /*--Give Empire--*/
                    if(EmpireAvailable){
                        EmpireComps += Companies
                        LifetimeMonths += AvailableCreds
                        Months += AvailableCreds
                        TotalMonths += AvailableCreds
                        NYPrestiges += 1
                        $("#Months").html(Months)
                        if(AvailableCreds>=6 && ACHvars.HalfYear==0){ACHvars.HalfYear+=1}
                        EmpireReset()
                        AllChecks()
                        Analytics('event', 'NewYear', {'event_category':"Prestige", "NYPrestiges": NYPrestiges,"EarnedCreds":AvailableCreds })
                        if(kongregate){kongregate.stats.submit('Earned Months', AvailableCreds)}
                    }
            }
            function EmpireReset(){
                /*-Reset Company Variables-*/
                Companies = 0
                HPoints = 0
                StoreThresh = 20
                cMultiplier = 1
                $(".CompanyUpgrade").css("background-color","")
                for(var cUPr in hUpgrades){
                    if(cUPr=="PermaBuyers"){
                        if(NYUpgrades.RetainPermas=="no"){
                            for(var cPerma in hUpgrades.PermaBuyers){
                                hUpgrades.PermaBuyers[cPerma] = "no"
                            }
                        }
                    }else{
                        if(NYUpgrades.PermaBuyers[cUPr]){
                            if(NYUpgrades.PermaBuyers[cUPr]=="no"&&cUPr!="AutoStoreOn"&&cUPr!="AutoStoreAMT"){
                                hUpgrades[cUPr] = "no"
                            }
                        }else{
                            if(cUPr=="PermaAutoUpgrades"){
                                if(NYUpgrades.RetainAutomation=="no"){
                                    hUpgrades[cUPr] = "no"
                                }
                            }else if(cUPr=="PermaBelUpgrades"){
                                if(NYUpgrades.RetainPermas=="no"){
                                    hUpgrades[cUPr] = "no"
                                }
                            }
                        }
                    }
                }

                /*--Reset Basic Variables--*/
                    TotalScore = 0
                    LifetimeScore = 0
                    BasicMultiplier = 1
                    StopAllUnlocked = "no"
                    if(NYUpgrades.RetainAutomation=="no"){
                        AutoSpinUnlocked = "no"
                        AutoStopUnlocked = "no"
                        AutoStopSpeed = 1000
                        /*--Stop Reels--*/
                            for(var ReelStop = 1;ReelStop<=5;ReelStop++){
                                Machines[ReelStop].stop()
                            }
                            $("#SpinReels").prop("disabled",false)
                    }
                /*--Reset Loyalty Variables--*/
                    Believers = 0
                    VisibleLines = 3
                    BelieverMulti = 1
                    FlakeIsWild = "no"
                /*--Reset Automators--*/
                    //if(hUpgrades["PermaBuyers"]=="no"){
                        for(var Automator in Automators){
                            permaed = hUpgrades.PermaBuyers[Automator.replace("auto","")]=="yes"||Automator=="autoMoneyPoints"||Automator=="autoCompanyPoints"
                            if(!permaed){
                                var aUpgrade = Automator.replace("auto","a")
                                var HireFire = $(".StoreHolder#"+aUpgrade).find(".HireFire")
                                HireFire.html("Hire")
                                $(this).find(".Upgrade").prop("disabled",true)
                                $(this).find(".Upgrade").css("background-color","grey")
                                Automators[Automator] = "no"
                            }
                        }
                    //}
                /*--Reset Store--*/
                    Stores = 0
                    Income = 0
                    sMultiplier = 1
                    IncomeInterval = 1000

                    IncomeCheck()
                    Money = 0
                /*--Reset Costs--*/
                    for(var RegUp in BaseCosts){
                        $(".UpgradeHolder#"+RegUp).find(".Cost").html(DisplayLarge(BaseCosts[RegUp]))
                    }
                    for(var lUp in BaseLCosts){
                        $(".BelUpgradeHolder#"+lUp).find(".Cost").html(DisplayLarge(BaseLCosts[lUp]))
                    }
                    for(var sUp in BaseSCosts){
                        $(".StoreHolder#"+sUp).find(".Cost").html(DisplayLarge(BaseSCosts[sUp]))
                    }
                    for(var cUp in BaseCCosts){
                        $(".CompanyHolder#"+cUp).find(".Cost").html(DisplayLarge(BaseCCosts[cUp]))
                    }
                /*--Display Variables--*/
                    $("#AvailBelievers").html(0)
                    $(".Believers").each(function(){
                        $(this).html(DisplayLarge(Believers))
                    })
                    $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
                /*--Save Variables--*/
                    SaveData()
                /*--Check Updates--*/
                    AllChecks()
            }
        /*--Empire Upgrades--*/
            var AutoPerma = ["AutoSpin","AutoStop","StoppingSpeed","GetStopAll"]
            function EmpireUpgrade(eID){
                var ECCost = Number($(".EmpireHolder#"+eID).find(".Cost").html())
                if(Months>=ECCost){
                    Analytics('event', 'Upgrade', {'event_category':"Empire", 'event_label':eID})
                    if($(".EmpireHolder#"+eID).hasClass("Auto")){
                        Months -= ECCost
                        Automators[eID] = "yes"
                    }else if($(".EmpireHolder#"+eID).hasClass("Perma")){
                        Months -= ECCost
                        var PermaGrade = eID.replace("Perma","")
                        NYUpgrades.PermaBuyers[PermaGrade] = "yes"
                        hUpgrades[PermaGrade] = "yes"
                    }else if($(".EmpireHolder#"+eID).hasClass("Binary")){
                        Months -= ECCost
                        NYUpgrades[eID] = "yes"
                        switch(eID){
                            case "RetainPermas":
                                for(var CPerma in hUpgrades.PermaBuyers){
                                    if(!AutoPerma.includes(CPerma)){
                                        hUpgrades.PermaBuyers[CPerma] = "yes"
                                        Automators["auto"+CPerma] = "yes"
                                    }
                                }
                                hUpgrades.PermaBelUpgrades = "yes"
                                break;
                            case "RetainAutomation":
                                for(var CPid in AutoPerma){
                                    hUpgrades.PermaBuyers[AutoPerma[CPid]] = "yes"
                                    Automators["auto"+AutoPerma[CPid]] = "yes"
                                }
                                hUpgrades.PermaAutoUpgrades = "yes"
                                break;
                        }
                    }else{
                        switch(eID){
                            case "EmpireIncomeMulti":
                                Months -= ECCost
                                NYUpgrades.EmpireIncomeMulti *= 2
                                if(Stores>0){
                                    Stores *= 2
                                    Income *= 2
                                }
                                ECCost *=4
                                if(NYUpgrades.EmpireIncomeMulti==2){
                                    ECCost = 15
                                }
                                $(".EmpireHolder#"+eID).find(".Cost").html(ECCost)
                                break;
                            case "EmpireMulti":
                                Months -= ECCost
                                NYUpgrades.EmpireMulti *= 3
                                ECCost += 2
                                $(".EmpireHolder#"+eID).find(".Cost").html(ECCost)
                                break;
                            case "StoreMulti":
                                Months -= ECCost
                                NYUpgrades.StoreMulti = 4
                                break;
                            case "CompMulti":
                                Months -= ECCost
                                NYUpgrades.CompMulti = 7
                                break;
                            case "NewGame":
                                var NewNGMulti = Math.floor(Math.sqrt(TotalMonths))*NGMulti
                                BasicConfirm("New Game+","Are you completely sure you would like to restart the game with a multiplier of "+DisplayLarge(NewNGMulti)+"x?<br><br>Thank you for playing!","NewGamePlus()")
                                break;
                        }
                    }
                    //console.log(NYUpgrades)
                }
                AllChecks()
            }
    /*------New Game+-------*/
        var NGMulti = 1
        var NGamt = 0
        function NewGamePlusCheck(){
            var AvailableNGMulti = Math.floor(Math.sqrt(TotalMonths))
            $("#AvailNGM").html(AvailableNGMulti.toFixed(0))
        }
        function NewGamePlus(){
            var AvailableNGMulti = Math.floor(Math.sqrt(TotalMonths))
            NGMulti *= AvailableNGMulti
            NGamt += 1
            /*-Reset Empire Variables-*/
                EmpireComps = 0
                Months = 0
                TotalMonths = 0
                NYPrestiges = 0

                NYUpgrades ={
                    EmpireIncomeMulti: 1,
                    EmpireMulti: 1,
                    AutoCompanies: "no",
                    MultiComp: "no",
                    AutoCompanyAMT: 1,
                    AutoCompanyOn: "no",
                    RetainAutomation: "no",
                    RetainPermas: "no",
                    AutoCompanySpin: "no",
                    StoreMulti: 3,
                    CompMulti: 5,
                    PermaBuyers: {
                        AutoDelivery: "no",
                        FirstSpin: "no",
                        MultiStores: "no",
                        AutoStores: "no"
                    }
                }
            
            /*-Reset Company Variables-*/
                Companies = 0
                HPoints = 0
                StoreThresh = 20
                cMultiplier = 1
                $(".CompanyUpgrade").css("background-color","")
                for(var cUPr in hUpgrades){
                    if(cUPr=="PermaBuyers"){
                        //if(NYUpgrades.RetainPermas=="no"){
                            for(var cPerma in hUpgrades.PermaBuyers){
                                hUpgrades.PermaBuyers[cPerma] = "no"
                            }
                        //}
                    }else{
                        //if(NYUpgrades.PermaBuyers[cUPr]=="no"){
                            hUpgrades[cUPr] = "no"
                        //}
                    }
                }

            /*--Reset Basic Variables--*/
                TotalScore = 0
                LifetimeScore = 0
                BasicMultiplier = 1
                StopAllUnlocked = "no"
                AutoSpinUnlocked = "no"
                AutoStopUnlocked = "no"
                AutoStopSpeed = 1000
            /*--Reset Loyalty Variables--*/
                Believers = 0
                VisibleLines = 3
                BelieverMulti = 1
                FlakeIsWild = "no"
            /*--Reset Automators--*/
                //if(hUpgrades["PermaBuyers"]=="no"){
                    for(var Automator in Automators){
                        //permaed = hUpgrades.PermaBuyers[Automator.replace("auto","")]=="yes"||Automator=="autoMoneyPoints"||Automator=="autoMoneyIcons"||Automator=="autoCompanyPoints"
                        //if(!permaed){
                            var aUpgrade = Automator.replace("auto","a")
                            var HireFire = $(".StoreHolder#"+aUpgrade).find(".HireFire")
                            HireFire.html("Hire")
                            $(this).find(".Upgrade").prop("disabled",true)
                            $(this).find(".Upgrade").css("background-color","grey")
                            Automators[Automator] = "no"
                        //}
                    }
                //}
            /*--Reset Store--*/
                Stores = 0
                Income = 0
                sMultiplier = 1
                IncomeInterval = 1000

                IncomeCheck()
                Money = 0
            /*--Reset Costs--*/
                for(var RegUp in BaseCosts){
                    $(".UpgradeHolder#"+RegUp).find(".Cost").html(DisplayLarge(BaseCosts[RegUp]))
                }
                for(var lUp in BaseLCosts){
                    $(".BelUpgradeHolder#"+lUp).find(".Cost").html(DisplayLarge(BaseLCosts[lUp]))
                }
                for(var sUp in BaseSCosts){
                    $(".StoreHolder#"+sUp).find(".Cost").html(DisplayLarge(BaseSCosts[sUp]))
                }
                for(var cUp in BaseCCosts){
                    $(".CompanyHolder#"+cUp).find(".Cost").html(DisplayLarge(BaseCCosts[cUp]))
                }
                for(var eUp in BaseECosts){
                    $(".EmpireHolder#"+eUp).find(".Cost").html(DisplayLarge(BaseECosts[eUp]))
                }
                $(".EmpireUpgrade").each(function(){
                    $(this).attr("style","")
                })
            /*--Close Popup--*/
                $(".Popup").hide()
                $(".PopupHolder").hide()
            /*--Display Variables--*/
                $("#AvailBelievers").html(0)
                $(".Believers").each(function(){
                    $(this).html(DisplayLarge(Believers))
                })
                $(".TotalAMT").each(function(){$(this).html(DisplayLarge(TotalScore))})
            /*--Stop Reels--*/
                for(var ReelStop = 1;ReelStop<=5;ReelStop++){
                    Machines[ReelStop].stop()
                }
            /*--Save Variables--*/
                SaveData()
            /*--Check Updates--*/
                AllChecks()
            /*--Log it--*/
                Analytics('event', 'Reset', {'event_category':"NewGame+", "EarnedMulti": AvailableNGMulti,"TotalNGMulti":NGMulti })
                if(kongregate){kongregate.stats.submit('Log10 NG+ Multi', Math.log10(NGMulti))}
        }

    /*------Purchasing-------*/
        function onPurchaseResult(success,thePurchase){
            //console.log("Purchase of "+thePurchase+" is "+ success)
            if(success){
                HandlePurchase(thePurchase)
                EventID = thePurchase + " Purchase"
                Analytics('event', 'Purchase', {'event_category':"Donations", 'event_label': thePurchase })
                //theUser = kongregate.services.getUsername()
                //kongregate.mtx.requestUserItemList(kongregate.services.getUsername(), Purchases)
            }
        }
        function Purchases(UserPurchases){
            //console.log(UserPurchases)
            for(var purchase in UserPurchases["data"]){
                thePurchase = UserPurchases["data"][purchase]
                //console.log(UserPurchases["data"][purchase])
                if(thePurchase.identifier != "warpdonation"){
                    HandlePurchase(thePurchase.identifier)
                }
                //console.log("D:"+DonationMulti+" L:"+LoyaltyMulti+" I:"+PurchaseIcons)
            }
            UpgradeCheck()
        }
        function HandlePurchase(thePurchase){
            switch(thePurchase){
                case "triplerdonation":
                    DonationMulti *= 3
                    $("#DonationMulti").html(DonationMulti)
                    Analytics('event', 'Verified', {'event_category':"Donations", 'event_label': thePurchase })
                    break;
                case "believerdonation":
                    DonationBelMulti *= 3
                    $("#DonationBelMulti").html(DonationBelMulti)
                    Analytics('event', 'Verified', {'event_category':"Donations", 'event_label': thePurchase })
                    break;
                case "storedonation":
                    ExtraIncome += .1
                    $("#YearPerStore").html(((100+(ExtraIncome*500)) * NYUpgrades.EmpireIncomeMulti).toFixed(0))
                    $("#MinPerStore").html(((20+(ExtraIncome*100)) * NYUpgrades.EmpireIncomeMulti).toFixed(0))
                    $("#ExtraIncome").html((ExtraIncome* NYUpgrades.EmpireIncomeMulti).toFixed(2))
                    $("#IncomeAdd").html(((10)* NYUpgrades.EmpireIncomeMulti))
                    //var NewStores = Math.round(((.2+ExtraIncome)/(.1+ExtraIncome))*Stores)
                    //console.log(NewStores,NewStores/5,(NewStores/5)-(Stores/5),Income+((NewStores/5)-(Stores/5)))
                    Analytics('event', 'Verified', {'event_category':"Donations", 'event_label': thePurchase })
                    break;
                case "warpdonation":
                    var NewMoney = 0
                    var Warp = 60*2
                    NewMoney = Number(((Income*Warp)).toFixed(2))
                    Money += NewMoney
                    BasicPopup("Offline Progress","Welcome Back!<br><br>You were offline for 4 Hours. You earned 100% of your Store Income and gained: $"+NewMoney.toFixed(2))
                    Analytics('event', 'Verified', {'event_category':"Donations", 'event_label': thePurchase })
                    break;
            }
        }
    /*------Achievements-------*/
        var ACHcount = 0
        var ACHmulti = 1
        var ACHchange = 0

        var Achievements = {
            ACHStart: 0,
            ACHAllIcons: 0,
            ACHJackPot: 0,
            ACHActive: 0,
            ACHFail: 0,
            ACHBells: 0,
            ACHIdling: 0,
            ACHAwake: 0,
            ACHRPA: 0,
            ACHDelivery: 0,
            ACHNoFlake: 0,
            ACHStoreAmt: 0,
            ACHAutoDoubler: 0,
            ACHElara: 0,
            ACHBasicAuto: 0,
            ACHAllAuto: 0,
            ACHConvert: 0,
            ACHSynergy: 0,
            ACHAllNights: 0,
            ACHHindsight: 0,
            ACHHalfYear: 0,
            ACHYouWin: 0,
            ACHNewGame: 0,
        }
        var ACHvars = {
            Varied: 0,
            vCounts: {
                "bell": 0,
                "hat": 0,
                "flake": 0,
                "dreidel": 0,
                "present": 0,
                "ornaments": 0,
                "wreath": 0,
                "wild": 0,
            },
            JackPot: 0,
            Bells: 0,
            Fails: 0,
            Actives: 0,
            AutoSwitch: "no",
            YouWin: "no",
            HalfYear: 0
        }
        function AchievementInit(){
            $(".Achieve").mousemove(function(e) {
                //find X & Y coodrinates
                var x = e.clientX
                var y = e.clientY
                var TipText = $(this).attr("data-tooltip")
                var CurrentLeft = $(this).offset().left
                var CurrentTop = $(this).offset().top
                //console.log(CurrentTop)
                $(".AchieveTip2").html(TipText)
                $(".AchieveTip2").show()
                //Set tooltip position according to mouse position
                var Thetop = (CurrentTop - 30) + 'px';
                var Theleft = (CurrentLeft + 20) + 'px';
                $(".AchieveTip2").css({top: Thetop,left:Theleft})
            });
            $(".Achieve").mouseleave(function(e) {
                $(".AchieveTip2").hide()
                //console.log($(this).attr("id"))
                $(this).find(".NewACH").remove()
            })
            var UnearnedBox = "&#x2610;"
            $(".Achieve").each(function(){
                $(this).prepend("<span class='CheckMark'>"+UnearnedBox+"</span>")
            })
            $("#AchieveMenu").on('click', function() {
                AchievementCheck()
                ACHchange = 0
                $(".WaitingACH").hide()
                $(".WaitingACH").html(ACHchange)
                InterACH = setInterval(function(){
                    AchievementCheck()
                    //console.log("Running")
                    ACHchange = 0
                    $(".WaitingACH").hide()
                    $(".WaitingACH").html(ACHchange)
                },1250)
            })
            AchievementCheck()
        }
        function AchievementAmount(){
            var TotalAch = 0
            for(var ACH in Achievements){
                TotalAch += Achievements[ACH]
            }
            ACHcount = TotalAch
            return TotalAch
        }
        function AchievementCheck(){
            var StartCount = AchievementAmount()
            AwardAchievements()
            var EndCount = AchievementAmount()
            ACHcount = EndCount
            ACHchange += (EndCount - StartCount)
            if(ACHchange>0){
                $(".WaitingACH").show()
            }else{
                $(".WaitingACH").hide()
            }
            $(".WaitingACH").html(ACHchange)
            $("#AchievementsCount").html(ACHcount)
            var ACHbonus = (ACHcount*.05)
            $("#AchBonus").html((ACHbonus*100).toFixed(0))
            if((HPoints+Income+Months)>0){
                ACHmulti = 1+(ACHbonus*(HPoints+Income+Months))
            }else{
                ACHmulti = 1
            }
            $("#TotalAchBonus").html(ACHmulti.toFixed(2))
            AchievementDisplay()
            if(ACHchange>0){
                if(kongregate){kongregate.stats.submit('Achievements', ACHcount)}
            }
        }
        function AwardAchievements(){
            var ACHid
            var Metric
            var Requirement
            var Qualifier
            if(ACHvars.Varied<8){
                var Variance = 0
                for(var anIcon in ACHvars.vCounts){
                    Variance += ACHvars.vCounts[anIcon]
                }
                ACHvars.Varied = Variance
            }
            $(".Achieve").each(function(){
                ACHid = $(this).attr("id")
                var ACHbase = ACHid.replace("ACH","")
                var HasLevels = $(this).attr("data-atype")=="Levels"
                if(!(Achievements[ACHid]>0)||HasLevels){
                    switch(ACHbase){
                        case "Start":
                            Metric = BasicMultiplier
                            Requirement = 2
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "AllIcons":
                            Metric = ACHvars.Varied
                            Requirement = 8
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "JackPot":
                            Metric = ACHvars.JackPot
                            Requirement = 1
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Active":
                            Metric = ACHvars.Actives
                            Requirement = 5 * Math.pow(5,Achievements[ACHid])
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Fail":
                            Metric = ACHvars.Fails
                            Requirement = 10 * Math.pow(10,Achievements[ACHid])
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Bells":
                            Metric = ACHvars.Bells
                            Requirement = 100 * Math.pow(10,Achievements[ACHid])
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Idling":
                            Qualifier = (AutoSpinUnlocked=="yes"&&AutoStopUnlocked=="yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Awake":
                            Qualifier = (ACHvars.AutoSwitch == "yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "RPA":
                            Qualifier = (AutoStopSpeed<=200)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Delivery":
                            Metric = Believers
                            Requirement = 1
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "NoFlake":
                            Qualifier = (FlakeIsWild=="yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "StoreAmt":
                            Metric = Stores/NYUpgrades.EmpireIncomeMulti
                            Requirement = 1 * Math.pow(10,Achievements[ACHid])
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "AutoDoubler":
                            Qualifier = (Automators.autoDoubler=="yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Elara":
                            Qualifier = (Automators.autoAutoSpin=="yes"&&Automators.autoAutoStop=="yes"&&Automators.autoStoppingSpeed=="yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "BasicAuto":
                            Qualifier = (Automators.autoAutoSpin=="yes"&&Automators.autoAutoStop=="yes"&&Automators.autoStoppingSpeed=="yes"&&Automators.autoDoubler=="yes"&&Automators.autoGetStopAll=="yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "AllAuto":
                            Qualifier = (Automators.autoAutoSpin=="yes"&&Automators.autoAutoStop=="yes"&&Automators.autoStoppingSpeed=="yes"&&Automators.autoDoubler=="yes"&&Automators.autoGetStopAll=="yes"&&Automators.autoTripler=="yes"&&Automators.autoMoreLines=="yes"&&Automators.autoChangeFlake=="yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Convert":
                            Metric = Companies
                            Requirement = 1
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Synergy":
                            Metric = EmpireComps+Companies
                            Requirement = 5 * Math.pow(5,Achievements[ACHid])
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "AllNights":
                            Metric = 0
                            if(Companies>0){
                                for(var Night in hUpgrades){
                                    if(Night!="PermaBuyers"&&Night!="AutoStoreOn"){
                                        if(hUpgrades[Night]=="yes"){
                                            Metric += 1
                                        }
                                    }
                                }
                                if(hUpgrades.PermaBuyers.Doubler == "yes"){
                                    Metric += 1
                                }
                                if(hUpgrades.PermaBuyers.Tripler == "yes"){
                                    Metric += 1
                                }
                            }
                            Requirement = 8
                            //console.log(Metric)
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "Hindsight":
                            Metric = TotalMonths
                            Requirement = 1
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "HalfYear":
                            Metric = ACHvars.HalfYear
                            Requirement = 1
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "YouWin":
                            Qualifier = (ACHvars.YouWin=="yes")
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                        case "NewGame":
                            Metric = NGMulti
                            Requirement = 2
                            Qualifier = (Metric>=Requirement)
                            if(Qualifier){
                                Achievements[ACHid] += 1
                                $(this).prepend("<span class='NewACH'>! </span>")
                                Analytics('event', 'Earn', {'event_category':"Achievements", 'event_label':  ACHbase})
                            }
                            break;
                    }
                }
            })
        }
        function AchievementDisplay(){
            var EarnedCheck = "&#9745;"
            var UnearnedBox = "&#x2610;"
            var EarnedColor = "rgba(76, 175, 79, 0.729)"
            var UnearnedColor = "rgba(156, 114, 114, 0.35)"
            var LevelsColor = "rgba(76, 175, 79, 0.2)"
            //background: linear-gradient(to right, rgba(76, 175, 79, 0.729) 0%, rgba(102, 163, 104, 0.729) 40%,rgba(156, 114, 114, 0.35) 40%,rgba(156, 114, 114, 0.35) 100%);
            $(".Achieve").each(function(){
                var HasCheck = $(this).find(".CheckMark").length
                if(HasCheck){$(this).find(".CheckMark").remove()}
                var ACHid = $(this).attr("id")
                var ACHbase = ACHid.replace("ACH","")
                var HasLevels = $(this).attr("data-atype")=="Levels"
                if(Achievements[ACHid]>=1 && !HasLevels){
                    $(this).attr("class","Achieve Earned")
                    $(this).css("background",EarnedColor)
                    $(this).prepend("<span class='CheckMark'>"+EarnedCheck+"</span>")
                }else if(ACHbase=="AllIcons"){
                    Metric = ACHvars.Varied
                    Requirement = 8
                    var IconProgress = (Metric/Requirement)
                    var ProgressPercent = IconProgress * 100
                    var Background = "linear-gradient(to right, "+EarnedColor+" 0%, "+EarnedColor+" "+ProgressPercent+"%,"+UnearnedColor+" "+ProgressPercent+"%,"+UnearnedColor+" 100%)"
                    $(this).css("background",Background)
                    $(this).prepend("<span class='CheckMark'>"+UnearnedBox+"</span>")
                }else if(HasLevels){
                    var Progress = 0
                    switch(ACHbase){
                        case "Active":
                            var Metric = ACHvars.Actives
                            var Requirement = 5 * Math.pow(5,Achievements[ACHid])
                            Progress = (Metric/Requirement)
                            var aToolTip = "Manually Spin/Stop "+DisplayLarge(Requirement)+" Times ("+DisplayLarge(Metric)+"/"+DisplayLarge(Requirement)+")"
                            $(this).attr("data-tooltip",aToolTip)
                            $(this).find("#achNum").html(Achievements[ACHid]+1)
                            break;
                        case "StoreAmt":
                            var Metric = Stores/NYUpgrades.EmpireIncomeMulti
                            var Requirement = 1 * Math.pow(10,Achievements[ACHid])
                            Progress = (Metric/Requirement)
                            var aToolTip = "Buy "+Requirement+" Toy Stores ("+DisplayLarge(Metric)+"/"+DisplayLarge(Requirement)+")"
                            if(Requirement==1){aToolTip = "Buy 1 Toy Store"}
                            $(this).attr("data-tooltip",aToolTip)
                            $(this).find("#achNum").html(Achievements[ACHid]+1)
                            break;
                        case "Fail":
                            Metric = ACHvars.Fails
                            Requirement = 10 * Math.pow(10,Achievements[ACHid])
                            Progress = (Metric/Requirement)
                            var aToolTip = "Get 0 Points on "+DisplayLarge(Requirement)+" Spins ("+DisplayLarge(Metric)+"/"+DisplayLarge(Requirement)+")"
                            $(this).attr("data-tooltip",aToolTip)
                            $(this).find("#achNum").html(Achievements[ACHid]+1)
                            break;
                        case "Bells":
                            Metric = ACHvars.Bells
                            Requirement = 100 * Math.pow(10,Achievements[ACHid])
                            Progress = (Metric/Requirement)
                            var aToolTip = "Have "+DisplayLarge(Requirement)+" Bells Appear in Reels Overall ("+DisplayLarge(Metric)+"/"+DisplayLarge(Requirement)+")"
                            $(this).attr("data-tooltip",aToolTip)
                            $(this).find("#achNum").html(Achievements[ACHid]+1)
                            break;
                        case "Synergy":
                            var Metric = EmpireComps+Companies
                            var Requirement = 5 * Math.pow(5,Achievements[ACHid])
                            Progress = (Metric/Requirement)
                            var aToolTip = "Get "+Requirement+" Hanukkah Points ("+DisplayLarge(Metric)+"/"+DisplayLarge(Requirement)+")"
                            var isNew = ($(this).find(".NewACH").length > 0)
                            if(Metric==0){Metric=1}
                            var AchText = CompanyMan + " Got " + DisplayLarge(Math.abs(CMamt/Metric)) + "x" //<span id="CompanyMan">Wrt</span> Got <span id="ManAmount">1</span>x More This Week
                            if(Metric>CMamt){
                                AchText = AchText + " As Much This Week"
                            }else{
                                AchText = AchText + " More This Week"
                            }
                            $(this).html(AchText)
                            if(isNew){
                                $(this).prepend("<span class='NewACH'>! </span>")
                            }
                            $(this).attr("data-tooltip",aToolTip)
                            break;
                    }
                    $(this).attr("class","Achieve Partial")
                    if(Achievements[ACHid]>=1){
                        var ProgressPercent = Progress * 100
                        //console.log(ACHbase,ProgressPercent)
                        var Background = "linear-gradient(to right, "+EarnedColor+" 0%, "+EarnedColor+" "+ProgressPercent+"%,"+LevelsColor+" "+ProgressPercent+"%,"+LevelsColor+" 100%)"
                        $(this).css("background",Background)
                        $(this).prepend("<span class='CheckMark'>"+EarnedCheck+"</span>")
                    }else{
                        var ProgressPercent = Progress * 100
                        //console.log(ACHbase,ProgressPercent)
                        var Background = "linear-gradient(to right, "+EarnedColor+" 0%, "+EarnedColor+" "+ProgressPercent+"%,"+UnearnedColor+" "+ProgressPercent+"%,"+UnearnedColor+" 100%)"
                        $(this).css("background",Background)
                        $(this).prepend("<span class='CheckMark'>"+UnearnedBox+"</span>")
                    }
                }else{
                    $(this).attr("class","Achieve Unearned")
                    $(this).css("background",UnearnedColor)
                    $(this).prepend("<span class='CheckMark'>"+UnearnedBox+"</span>")
                }
            })
        }

